Run untrusted code with Vercel Sandbox

Authors

1 min read

Vercel Sandbox is a secure cloud resource powered by Fluid compute. It is designed to run untrusted code, such as code generated by AI agents, in isolated and ephemeral environments.

Sandbox is a standalone SDK that can be executed from any environment, including non-Vercel platforms. Sandbox workloads run in ephemeral, isolated microVMs via the new Sandbox SDK, supporting execution times up to 45 minutes.

import { Sandbox } from "@vercel/sandbox";
import { generateText } from 'ai';
const result = await generateText({
model: "anthropic/claude-4-sonnet-20250514",
prompt: `Write a Node.js script that prints a Haiku poem to stdout.`,
system: `
You are a developer that responds with the content of a single Node.js script.
You must include only the code without any markdown, nothing else.
Just include Javascript code and no characters before or after the code.
`,
});
const sandbox = await Sandbox.create();
await sandbox.writeFiles([
{ path: "script.js", stream: Buffer.from(result.text) },
]);
await sandbox.runCommand({
cmd: "node",
args: ["script.js"],
stdout: process.stdout,
stderr: process.stderr,
});

An example of using Vercel Sandbox to run generated code.

Sandbox uses the Fluid compute model and charges based on Fluid’s new Active CPU time, meaning you only pay for compute when actively using CPU. See Sandbox pricing for included allotments and pricing for Hobby and Pro teams.

Now in Beta and available to customers on all plans. Learn more about Vercel Sandbox.