content:Buffer.from("console.log('Hello from Vercel Sandbox!')\n"),
});
try {
constsandbox=awaitSandbox.create({
{
awaitsandbox.writeFiles([
}
},
]);
import { Sandbox } from'@vercel/sandbox';
timeout:60_000,
constresult=awaitsandbox.runCommand('node', ['hello.js']);
if (result.exitCode !==0) {
}
} finally {
thrownewError(awaitresult.stderr());
console.log(awaitresult.stdout());
awaitsandbox.stop();
path:'hello.js',
You can use any of the Vercel Managed Image, or start from your own or a shared custom image hosted on Vercel Container Registry. See Images for how to use it:
import { Sandbox } from'@vercel/sandbox';
constsandbox=awaitSandbox.create({
image:'my-repository:latest',
});
Resume a long-lived sandbox
Persistent sandboxes keep their filesystem across sessions. Create a sandbox, write a file, stop it, then resume by name and read the file back, with no snapshot ID to track and no setup to repeat.
TypeScript Python
awaitsandbox.writeFiles([
{
// First run: create a named sandbox, write a file, stop it.
path:'/vercel/sandbox/notes.txt',
constsandbox=awaitSandbox.create({ name:'my-sandbox' });
import { Sandbox } from'@vercel/sandbox';
// Later, in a separate process: resume the same sandbox by name and
]);
awaitsandbox.stop();
},
constresumed=awaitSandbox.get({ name:'my-sandbox' });
content:Buffer.from('Hello from the first session.\n'),
// read the file back. The next SDK call auto-resumes the session.
TypeScriptPython
});
timeout:3*60*60*1000,// 3 hours
console.log(sandbox.timeout);
import { Sandbox } from'@vercel/sandbox';
try {
} finally {
}
awaitsandbox.stop();
constsandbox=awaitSandbox.create({
By default, sandboxes timeout after 5 minutes. For longer tasks, set a custom timeout when creating the sandbox:
TypeScriptPython
try {
} finally {
constsandbox=awaitSandbox.create();
awaitsandbox.extendTimeout(2*60*60*1000); // Add 2 hours
import { Sandbox } from'@vercel/sandbox';
To extend a running sandbox, call extendTimeout in TypeScript or extend_timeout() in Python:
}
TypeScriptPython
awaitsandbox.stop();
See Pricing and Limits for maximum durations by plan.
Run a detached command and stream logs
Use a detached command when you need to follow long-running output, keep a server alive, or wait for completion later.
constsandbox=awaitSandbox.create({ timeout:120_000 });
cmd:'bash',
detached:true,
constcommand=awaitsandbox.runCommand({
try {
import { Sandbox } from'@vercel/sandbox';
}
});
} else {
forawait (constlineofcommand.logs()) {
if (line.stream ==='stdout') {
process.stdout.write(line.data);
process.stderr.write(line.data);
}
} finally {
}
constfinished=awaitcommand.wait();
console.log(finished.exitCode);
awaitsandbox.stop();
Prepare files and download artifacts
Use file APIs when your local application needs to send input files to the sandbox and retrieve a build output.
TypeScriptPython
import { Sandbox } from'@vercel/sandbox';
awaitsandbox.mkDir('src');
"import { mkdir, writeFile } from 'node:fs/promises';\n\n"+
content:Buffer.from(
try {
awaitsandbox.writeFiles([
{
{ mkdirRecursive:true }
"await mkdir('dist', { recursive: true });\n"+
awaitsandbox.stop();
),
},
thrownewError(awaitresult.stderr());
awaitsandbox.downloadFile(
"await writeFile('dist/output.txt', 'hello from sandbox\\n');\n"
]);
}
} finally {
);
Snapshot and restore a prepared environment
Use snapshots after dependency installation or environment setup so future sandboxes start from the same filesystem state. With persistent sandboxes, snapshots are also created automatically every time the sandbox stops; for manual checkpoints, call snapshot() explicitly.
To spawn fresh children from another sandbox's current snapshot without tracking IDs manually, use Sandbox.fork. The fork inherits the source's config and is seeded from its latest snapshot:
import { Sandbox } from'@vercel/sandbox';
constchild=awaitSandbox.fork({
sourceSandbox:'my-base-sandbox',
persistent:false,
});
TypeScript Python
constMIN_SNAPSHOT_EXPIRATION_MS=24*60*60*1000;
awaitsandbox.writeFiles([
constsandbox=awaitSandbox.create({ runtime:'node24' });
let snapshotId ='';
try {
awaitsandbox.stop();
]);
} catch (error) {
{ path:'config.json', content:Buffer.from('{"env": "prod"}') },
}
throw error;
});
timeout:120_000,
awaitrestored.stop();
constresult=awaitrestored.runCommand('cat', ['config.json']);
try {
});
} finally {
}
Debug with an interactive shell
Connect to a running sandbox for interactive debugging with an SSH-like experience:
See CLI Reference for all options.
sandbox connect
Once connected, you have full shell access to inspect logs, check processes, and explore the filesystem.
Monitor your sandbox
View your sandboxes in the Sandboxes dashboard. For each project, you can see:
- Total sandboxes created
- Currently running sandboxes
- Stopped sandboxes
- Command history and sandbox URLs
Track compute usage across projects in the Usage dashboard, which measures:
- Sandbox Provisioned Memory: Memory allocated to your sandboxes
- Sandbox Data Transfer: Data your sandboxes send to the internet, plus all traffic to and from exposed ports, is billable. Data your sandboxes download from the internet is free
- Sandbox Active CPU: CPU time consumed
- Sandbox Creations: Number of sandboxes created
- Snapshot Storage: Sandbox snapshot storage
Stop a sandbox
There are three ways to stop a sandbox:
Programmatically
TypeScriptPython
// Run your workflow here.
- Go to Sandboxes in Observability.
- Select your sandbox.
- Click Stop Sandbox.
try {
}
} finally {
awaitsandbox.stop();
constsandbox=awaitSandbox.create();
import { Sandbox } from'@vercel/sandbox';
Stopping a persistent sandbox ends the current session but keeps the sandbox so it can be resumed later. To remove the sandbox along with all of its sessions, delete it. This cannot be undone. Deleting a sandbox keeps its snapshots, which stay available until they expire or you delete them.
You can reach our customer support team by emailing info@yourcompany.example.com, calling +1 555-555-5556, or using the live chat on our website. Our dedicated team is available 24/7 to assist with any inquiries or issues.
We’re committed to providing prompt and effective solutions to ensure your satisfaction.
We offer a 30-day return policy for all products. Items must be in their original condition, unused, and include the receipt or proof of purchase. Refunds are processed within 5-7 business days of receiving the returned item.
- Go to Sandboxes in Observability and select the sandbox you want to delete.
- Scroll to the Delete Sandbox section at the bottom of the detail page.
- Click Delete Sandbox.
- In the confirmation modal, type the sandbox name and the verification phrase delete my sandbox, then click Delete Sandbox.
Use sandbox.delete() from the JS SDK to remove the sandbox in code. This is useful for cleanup at the end of a job or when reacting to an event:
import { Sandbox } from'@vercel/sandbox';
constsandbox=awaitSandbox.get({ name:'my-sandbox' });
awaitsandbox.delete();
Run sandbox remove for ad-hoc cleanup or to script deletion alongside other CLI commands:
You can reach our customer support team by emailing info@yourcompany.example.com, calling +1 555-555-5556, or using the live chat on our website. Our dedicated team is available 24/7 to assist with any inquiries or issues.
We’re committed to providing prompt and effective solutions to ensure your satisfaction.
We offer a 30-day return policy for all products. Items must be in their original condition, unused, and include the receipt or proof of purchase. Refunds are processed within 5-7 business days of receiving the returned item.
Run AI-generated code
Learn how to run code generated by AI models in an isolated sandbox environment.
Run OpenCode securely with the Vercel Sandbox
Learn how to run OpenCode securely with the Vercel Sandbox to build your own background coding agent
Last updated September 15, 2026
Cross-link map: Working with Sandbox (/docs/sandbox/working-with-sandbox)From the Vercel docs graph (built 2026-09-21T05:26:59.511Z), spanning vercel.com docs + KB, nextjs.org, ai-sdk.dev, and other Vercel documentation sites. Full graph as JSON: https://vercel.com/docs/graph.jsonSemantically closest pagesUnderstanding Sandboxes — Learn how Vercel Sandboxes provide on-demand, isolated compute environments for running untrusted code, testing applicatVercel Sandbox — Run untrusted or agent-generated code in isolated Linux microVMs with Vercel Sandbox.Persistence — Sandboxes automatically save their filesystem state when stopped and restore it when resumed. No manual snapshot managemRunning commands in a Vercel Sandbox — Create isolated sandbox environments to run builds, tests, and commands safely.Quickstart — Learn how to run your first code in a Vercel Sandbox.This page links to (14)Sandbox CLI Reference — Based on the Docker CLI, you can use the Sandbox CLI to manage your Vercel Sandbox from the command line.Images — Start sandboxes from Vercel's Managed Images, or custom OCI images stored in Vercel Container Registry to ship your ownPersistence — Sandboxes automatically save their filesystem state when stopped and restore it when resumed. No manual snapshot managemSnapshots — Save and restore sandbox state with snapshots for faster startups and environment sharing.Vercel Sandbox pricing and quotas — Understand how Vercel Sandbox billing works, what's included in each plan, and the quotas that apply.JS SDK Reference — A comprehensive reference for the Vercel Sandbox JavaScript SDK, which lets you run code in a secure, isolated environmeRun Cursor Cloud Agents on Vercel Sandbox — Learn how to run Cursor Cloud Agents on Vercel Sandbox with BYOM worker pools, durable workflows, isolated microVMs, andHow to execute AI-generated code safely with Vercel Sandbox — Learn how to run code generated by AI models in an isolated sandbox environment.How to reconnect to a running Sandbox — Learn how to use \Sandbox.get\\(\\)\\ to reconnect to an existing sandbox from a different process or after a script restSafely running AI generated code in your Next.js application — How to execute untrusted, AI‑generated code from a Next.js app using Vercel Sandbox, an isolated, ephemeral environment.Running OpenClaw in Vercel Sandbox — This guide walks you through setting up OpenClaw inside a Vercel Sandbox and configuring the WhatsApp channel.Running OpenCode securely with the Vercel Sandbox — Run OpenCode in an isolated Vercel Sandbox MicroVM with controlled egress, using the SDK to restrict network access so tUsing private GitHub repositories with Vercel Sandbox — Learn how to use Vercel Sandbox with private GitHub repositories using fine-grained tokens, classic tokens, or GitHub ApUsing Vercel Sandbox to run Claude’s Agent SDK — Learn how to deploy Claude's Agent SDK in Vercel Sandbox for secure and isolated execution of AI-powered code generationPages that link here (7)By site: vercel-docs (7)Vercel Sandbox — Run untrusted or agent-generated code in isolated Linux microVMs with Vercel Sandbox.Understanding Sandboxes — Learn how Vercel Sandboxes provide on-demand, isolated compute environments for running untrusted code, testing applicatRun isolated AI agents in one sandbox — Give each AI agent an isolated Linux user in a Vercel Sandbox with the @vercel/sandbox createUser, createGroup, and asUsEcosystem — Use Vercel Sandbox with the agent frameworks, model SDKs, and coding agents you already work with.Vercel Sandbox pricing and quotas — Understand how Vercel Sandbox billing works, what's included in each plan, and the quotas that apply.Quickstart — Learn how to run your first code in a Vercel Sandbox.JS SDK Reference — A comprehensive reference for the Vercel Sandbox JavaScript SDK, which lets you run code in a secure, isolated environme