Claude Agent SDK

Run a Claude Agent SDK agent whose code runs in a Sandal sandbox instead of on your machine (TypeScript).


The Claude Agent SDK runs Claude Code as a library, with built-in Bash and file tools that act on the machine it runs on. To run the agent's code in an isolated sandbox instead, give it a Sandal tool through an in-process MCP server and turn the built-in tools off (tools: []).

Install the Sandal SDK from your beta bundle and sign in once with sandal login (the SDK reads that profile), or set SANDAL_API_KEY (the key alone is enough).

npm install @anthropic-ai/claude-agent-sdk zod   # plus the Sandal SDK (see above)
agent.mjs
import { query, tool, createSdkMcpServer } from "@anthropic-ai/claude-agent-sdk";
import { Sandal } from "@sandal-dev/sdk";
import { z } from "zod";

const sandal = new Sandal(); // the `sandal login` profile, or the SANDAL_* variables
const sb = await sandal.createSandbox();

const runPython = tool(
  "run_python",
  "Run Python 3 code in an isolated Sandal sandbox and return its exit code and output.",
  { code: z.string() },
  async ({ code }) => {
    await sb.writeText("/workspace/main.py", code);
    const r = await sb.exec("python3 /workspace/main.py");
    return { content: [{ type: "text", text: `exit ${r.exitCode}\n${r.stdout}${r.stderr}` }] };
  },
);
const sandalTools = createSdkMcpServer({ name: "sandal", version: "1.0.0", tools: [runPython] });

try {
  for await (const message of query({
    prompt: "What is the 30th Fibonacci number? Compute it with run_python.",
    options: {
      mcpServers: { sandal: sandalTools },
      allowedTools: ["mcp__sandal__run_python"],
      tools: [], // no built-in Bash/Read/Write: code runs only in the sandbox
    },
  })) {
    if (message.type === "result" && message.subtype === "success") console.log(message.result);
  }
} finally {
  await sb.delete();
}

Run it with ANTHROPIC_API_KEY set: node agent.mjs.

Verified against Sandal CLI/SDK 0.1.0-beta.10 on 2026-11-25: the tool was called directly and ran print(sum(range(10))) in a real sandbox (exit 0, 45). The model call itself needs your own model provider key. Tested with @anthropic-ai/claude-agent-sdk 0.3.332 and zod 4.

The Sandal MCP server sandal-mcp (from the CLI) can also be added to Claude Code itself; it runs locally over stdio, see MCP server.