Getting started
Run a first Claude Code turn in a local Docker Sandbox.
This guide uses Docker Sandboxes, which run on your machine with nothing to deploy. To run the agent on Google Cloud instead, start from ai-sdk-sandbox-cloud-run or ai-sdk-sandbox-gce: each begins with deploying its sandbox service. Choosing a sandbox compares them all.
Rather start from a project that runs?
The starter is these steps, ready: npx giget@latest gh:fpasquet/ai-sdk-harness/examples/starter my-agent, then npm install and npm start. The
Next.js starter is every package in one app, with a marketplace of
plugins, fetched the same way.
Install Docker Sandboxes
Follow the Docker Sandboxes guide to install the sbx CLI, then sign in:
sbx login
sbx ls # should answer without an errorInstall the packages
pnpm add ai-sdk-sandbox-sbx @ai-sdk/harness @ai-sdk/harness-claude-codeProvide a credential
The Claude Code harness reads it from the environment:
export CLAUDE_CODE_OAUTH_TOKEN=... # `claude setup-token`, for a Claude subscription
# or
export ANTHROPIC_API_KEY=sk-ant-...Only a placeholder of it ever enters the sandbox: the Docker Sandboxes proxy swaps the real value in on the way to Anthropic. Outside the sandbox, keeping it safe is up to your application: see Securing credentials.
Run a turn
import { HarnessAgent } from '@ai-sdk/harness/agent';
import { createClaudeCode } from '@ai-sdk/harness-claude-code';
import { createSbxNetworkSandboxSession } from 'ai-sdk-sandbox-sbx';
const agent = new HarnessAgent({ harness: createClaudeCode(), model: 'claude-haiku-4-5' });
const sandboxSession = await createSbxNetworkSandboxSession({
ports: [4000],
setup: ['npm install --global --silent pnpm@10'],
template: await agent.getSandboxTemplate(),
});
const session = await agent.createSession({ sandboxSession });
try {
const { text } = await agent.generate({
session,
prompt: 'Write a script that prints the first ten primes, then run it.',
});
console.log(text);
} finally {
await session.destroy();
await sandboxSession.destroy();
}npx tsx index.tsThe first run installs Claude Code in a sandbox and saves it as a template image, which takes a minute or two. The next ones start from it in seconds.
Next steps
- Add plugins to the agent: a hook that guards it, slash commands, skills and MCP servers.
- Resume a sandbox across processes instead of creating one per run.
- Mount your project so the agent works on your files.
- Work on a Python, Go or Rust project: an image with its toolchain, and its registries opened.
- Look at the Next.js starter for a streamed, multi-turn conversation.
Introduction
Community packages for the Vercel AI SDK harnesses, for Docker Sandboxes, microsandbox, Cloud Run sandboxes, Anthropic Sandbox Runtime, plugins, sessions and approvals.
Choosing a sandbox
Which sandbox package fits where your agent runs, which others exist, what any sandbox image needs, and how to work on a Python, Go or Rust project.