Vercel AI SDK
A Sandal sandbox as an AI SDK tool for generateText / streamText agents (TypeScript).
An AI SDK tool() that runs code in one Sandal sandbox; stopWhen lets the model call it several times.
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 ai zod # plus the Sandal SDK (see above)import { generateText, stepCountIs, tool } from "ai";
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({
description: "Run Python 3 code in an isolated Sandal sandbox and return its exit code and output.",
inputSchema: z.object({ code: z.string() }),
execute: async ({ code }) => {
await sb.writeText("/workspace/main.py", code);
const r = await sb.exec("python3 /workspace/main.py");
return { exitCode: r.exitCode, stdout: r.stdout, stderr: r.stderr };
},
});
try {
const { text } = await generateText({
model: "openai/gpt-5", // any AI SDK model; a provider string uses the AI Gateway
tools: { run_python: runPython },
stopWhen: stepCountIs(5),
prompt: "What is the 30th Fibonacci number? Compute it with run_python.",
});
console.log(text);
} finally {
await sb.delete();
}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 ai 7.0.182 and zod 4.