Skip to Content
ai-sdk-harness

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 error

Install the packages

pnpm add ai-sdk-sandbox-sbx @ai-sdk/harness @ai-sdk/harness-claude-code

Provide 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

index.ts
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.ts

The 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

On this page