cd /news/ai-agents/tanstack-ais-sandbox-api · home › topics › ai-agents › article
[ARTICLE · art-166213] src=blog.master.dev ↗ pub= topic=ai-agents verified=true sentiment=↑ positive

TanStack AI’s Sandbox API

TanStack AI's Sandbox API lets developers drive Claude Code in a remote cloud sandbox to clone a GitHub repository, branch it, add a requested feature and open a pull request, according to a tutorial published on the Master.dev blog. The walkthrough configures a GitHub personal access token with read/write access to Contents and Pull requests, an Anthropic API key, and provider credentials for Vercel (VERCEL_TOKEN, VERCEL_TEAM_ID, VERCEL_PROJECT_ID) or Railway (project and environment IDs). The author positions the approach as a slower, paid alternative to pairing a laptop with a phone via tools like T3 and Codex, suited to occasional use when no always-on machine is available.

by read7 min views3 publishedNov 9, 2026
TanStack AI’s Sandbox API
Image: Blog (auto-discovered)

TanStack AI is a fantastic SDK for integrating AI features into software. I’ve written about it here and here. Those posts covered basic prompt-based requests; we provided context and asked AI to generate some workouts for us. We went through streaming, persistence, and structured output.

This post is about doing actual agentic work through TanStack AI, via their Sandbox API. Specifically, we’ll use TanStack AI to drive Claude Code in a remote sandbox, make changes to a GitHub repo, and open a pull request. Why would you want to do this? Sometimes you’re away from your computer with some downtime and nothing better to do than get a few tasks done.

I want to be clear: this is already possible with tools like T3, Codex, etc. You can pair your laptop and your phone, and drive the former from the latter. But your laptop needs to be up and running for that to work. Ideally, you’d have a PC set up and always on, running a simple Linux distro, for this very purpose. But if you don’t have that set up, and don’t care to, what I’ll show you here is a decent next-best alternative. It won’t be nearly as fast, and you’ll have to pay a small amount to providers like Vercel or Railway to use the remote sandboxes. But as an occasional fill-in, it’s more than good enough in my opinion.

#

I have a dirt-simple web app here. It has pages for different programming languages, with brief descriptions of each. I also have some admin pages that let me add features by prompting Claude Code in a remote sandbox with GitHub access.

The app has admin pages for Vercel and Railway, and both providers can clone our repo, branch, add the requested feature, and open a PR.

Let’s take a look!

#

You’ll need a few tokens. We’ll use Claude Code in our sandbox and connect it to GitHub so we can clone the repo and create PRs.

Let’s set up GitHub first. Go over to https://github.com/settings/personal-access-tokens and generate a new token. Make sure you select either “All Repositories” or “Only select repositories” (and select the repositories you want to provide access to). Then, for permissions, choose “Contents” and “Pull requests” with read/write access, and Metadata should auto-populate.

Generate the token and copy it into this environment var:

GH_TOKEN="github_pat_abc_xyz"

Next, head over to the Anthropic console, generate an API key, and copy it into a new env var:

ANTHROPIC_API_KEY="sk-ant-xyz-abc"

#

We’ll be running code in a cloud sandbox. TanStack AI supports a lot of different options. We’ll cover Vercel and Railway here, but of course check the docs if you want to use something else.

If you want to use Vercel, we’ll need three new env vars.

First, head over to your account settings page, which you can access from the bottom left.

Click that top section with your name and email, then click the tokens link in the left nav. Create your token, and add it into this env var:

VERCEL_TOKEN="vcp_abc_xyz"

Next, go to your Vercel team in the top left, then click on Settings, and grab your team ID.

Copy it into a new env var:

VERCEL_TEAM_ID="team_xyz"

Lastly, create the Vercel project you want to associate with this work, click Settings, and copy the project ID.

Then add it:

VERCEL_PROJECT_ID="prj_kBL24CmynuMNcclr4k5s55lqg2xf"

If you want to use Railway, you’ll need two values. First, for the environment ID, go to the project settings page and click Environments. It should look something like this:

It’s a little wonky, but look at the URL, and you should see something like this:

?environmentId=abcd-efgh-ijkl

Grab that environmentId and put it in a new env var:

RAILWAY_ENVIRONMENT_ID="abcd-efgh-ijkl"

Then, hit the tokens link on the same page in the left navigation list, create yourself a token, and, as always, add it as a new env var:

RAILWAY_TOKEN="c0903fad-4336-4f0f-a0bf-3edc7abcfc51"

#

If you’ve read my prior posts on TanStack AI, almost everything is the same. Persistence, resumability with a memory stream, etc., are all the same. The main difference is that, rather than routing our request through something like Vercel’s AI Gateway, we’ll provide a sandbox where the chat function can execute our request. That sandbox will have access to Claude Code and GitHub (via the setup we did above). This allows it to clone our repo, do work, and open pull requests.

We’ll review Vercel and Railway sandboxes, then put them to work.

Here’s my code for creating a Vercel sandbox:

import { createSecrets, defineSandbox, defineWorkspace, githubRepo } from "@tanstack/ai-sandbox";
import { vercelSandbox } from "@tanstack/ai-sandbox-vercel";

export const sandboxVercel = defineSandbox({
  id: "repo-agent",
  provider: vercelSandbox({}),
  workspace: defineWorkspace({
    source: githubRepo({ repo: "arackaf/tanstack-ai-sandboxes-blog-post" }),
    setup: [
      "sudo npm install -g @anthropic-ai/claude-code",

      "sudo dnf install -y 'dnf-command(config-manager)'",
      "sudo dnf config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo",
      "sudo dnf install -y gh",

      "npm install",
    ],
    secrets: createSecrets({
      ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY ?? "",
      GH_TOKEN: process.env.GH_TOKEN ?? "",
    }),
    instructions:
      "Accomplish the user's request and create a pull request. To publish work: run `gh auth setup-git` once, then `git push -u origin <branch>` and `gh pr create`. GH_TOKEN is already in the environment.",
  }),
  lifecycle: { reuse: "thread" },
});

Vercel requires a few more setup steps than Railway because its default container doesn’t include the GitHub CLI or Claude Code, so we have to install them ourselves. Also note this line:

lifecycle: { reuse: "thread" },

This tells TanStack AI to reuse the same sandbox within the same threadId (on the same server instance), so follow-up prompts and clarifications should maintain context.

Railway is pretty similar, but with less setup, since their sandbox image comes with more batteries included.

import { createSecrets, defineSandbox, defineWorkspace, githubRepo } from "@tanstack/ai-sandbox";
import { railwaySandbox } from "@tanstack/ai-sandbox-railway";

export const sandboxRailway = defineSandbox({
  id: "repo-agent",
  provider: railwaySandbox({}),
  workspace: defineWorkspace({
    source: githubRepo({
      repo: "arackaf/tanstack-ai-sandboxes-blog-post",
    }),
    setup: ["npm install"],
    secrets: createSecrets({
      ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY ?? "",
      GH_TOKEN: process.env.GH_TOKEN ?? "",
    }),
    instructions:
      "Accomplish the user's request and create a pull request. To publish work: run `gh auth setup-git` once, then `git push -u origin <branch>` and `gh pr create`. GH_TOKEN is already in the environment.",
  }),
  lifecycle: { reuse: "thread" },
});

#

With all that set up, everything else is the same. If you’ve read my prior posts on TanStack AI, you now have pretty much everything you need to run code inside of a sandbox, with access to your GitHub repository. Here’s what my call to chat in my API endpoint looks like:

const stream = chat({
  adapter: claudeCodeText("claude-opus-4-8"),
  messages,
  threadId,
  runId,
  middleware: [withPersistence(chatPersistence), withSandbox(sandboxVercel)],
});

The sandbox is simply a new middleware entry.

If you want to see the full code, the repo is here.

#

Let’s make a feature request on the Vercel route.

We can see the actual sandbox if we go to our Vercel dashboard:

Eventually, our PR is created:

#

You’ll probably want to clean up the resources you’ve created. Our sandbox object has a destroy method, and we’ll also want to remove the relevant rows from the persistence DB. Here’s what my Vercel cleanup looks like:

import { createServerFn } from "@tanstack/react-start";
import { eq } from "drizzle-orm";

import { db } from "../drizzle/db";
import { chatRuns, chatThreads } from "../drizzle/schema";
import { sandboxVercel } from "#/lib/vercel-sandbox";

export const deleteVercelSession = createServerFn({ method: "POST" })
  .validator((data: { threadId: string }) => data)
  .handler(async ({ data }) => {
    const { threadId } = data;
    const runs = await db.select({ runId: chatRuns.runId }).from(chatRuns).where(eq(chatRuns.threadId, threadId));

    try {
      console.log("Deleting threadId " + threadId + " ...");
      for (const run of runs) {
        await sandboxVercel.destroy({ runId: run.runId, threadId });
      }
      await db.delete(chatRuns).where(eq(chatRuns.threadId, threadId));
      await db.delete(chatThreads).where(eq(chatThreads.threadId, threadId));
      console.log("Deleted");
    } catch (error) {
      console.log("error deleting vercel sandbox\n\n", error);
      throw error;
    }
  });

Railway is identical except, of course, we call destroy on sandboxRailway.

Note: As of this writing, the Vercel cleanup provided by @tanstack/ai-sandbox-vercel isn’t quite… effective. The sandbox is only stopped, not deleted, and any disk snapshots aren’t deleted either. Hopefully this will be fixed soon, but whip up a cleanup script using the Vercel API if you plan to use it.

Railway does not have this problem. That said, Railway doesn’t delete disk checkpoints, but you’re not charged for them.

#

TanStack AI’s Sandbox API is a joy to use. It makes remote AI request execution a breeze. The flow, performance, and overall UX don’t quite compare to running Claude Code or Codex directly, but when you’re away from your laptop, it gets the job done well enough.

── more in #ai-agents 4 stories · sorted by recency
── more on @tanstack ai 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/tanstack-ais-sandbox…] indexed:0 read:7min 2026-11-09 · —