Skip to content
Sandbox SDK
Esc
↑↓navigate↵open⌘Jpreview
On this page

Vercel Sandbox

Use the Vercel Sandbox SDK (@vercel/sandbox) from TypeScript through one portable API. OIDC auth, exact keys, vCPU sizing, network policies and previews.

vercel() runs each sandbox as a Vercel Sandbox microVM through the official @vercel/sandbox SDK.

@vercel/sandbox is Vercel’s own Sandbox SDK. With @opencoredev/sandbox-sdk you call createSandbox(vercel()) and then box.run, box.files and box.preview, and the same code runs on E2B or Daytona when you swap vercel() for e2b() or daytona(). Vercel Sandbox has no idle timeout or terminal through this API; the capability matrix lists what differs per provider, and box.native reaches the @vercel/sandbox object when you need the rest.

Install

npm install @opencoredev/sandbox-sdk @vercel/sandbox
pnpm add @opencoredev/sandbox-sdk @vercel/sandbox
yarn add @opencoredev/sandbox-sdk @vercel/sandbox
bun add @opencoredev/sandbox-sdk @vercel/sandbox

The adapter needs @vercel/sandbox 3.8 or later. Inside a Vercel deployment it authenticates with OIDC and needs no configuration. Elsewhere, set VERCEL_TOKEN, VERCEL_TEAM_ID, and VERCEL_PROJECT_ID, or run vercel env pull to get VERCEL_OIDC_TOKEN.

Quickstart

import { createSandbox } from "@opencoredev/sandbox-sdk";
import { vercel } from "@opencoredev/sandbox-sdk/vercel";

await using box = await createSandbox(vercel());
const result = await box.run("node --version");
console.log(result.stdout);

await using deletes the sandbox when the block ends.

What it supports

Feature Support Notes
Commands and streaming Yes Live output
Files Yes
Background processes Yes
Preview URLs Yes Public https://; declare up to 15 ports
Pause and resume Partial Files survive; running processes end. Not with persistent: false
Snapshots Yes With expiresInMs
Machine size Partial Presets, or whole vCPUs at 2048 MiB each; no disk setting
Network policy Yes "none", a host allow list, or a native policy
Hard lifetime (timeoutMs) Partial Per session; each resume starts a new one
Idle timeout (idleTimeoutMs) No
Keys Exact Sandbox name is a hash of the key
Terminal No

The capability matrix compares these with every other provider.

Run commands

Await box.run for the result, or iterate it to stream output as it arrives.

import { createSandbox } from "@opencoredev/sandbox-sdk";
import { vercel } from "@opencoredev/sandbox-sdk/vercel";

await using box = await createSandbox(vercel());
const result = await box.run("ls -la", { cwd: "/workspace", timeoutMs: 30_000 });
console.log(result.exitCode, result.stdout);

for await (const chunk of box.run("for i in 1 2 3; do echo $i; sleep 1; done")) {
  process.stdout.write(chunk.text);
}

Files

Relative paths resolve against /workspace. Pass mode to set permissions. Vercel applies it as part of the upload, so a new secret file is created with 0o600 rather than tightened afterward.

import { createSandbox } from "@opencoredev/sandbox-sdk";
import { vercel } from "@opencoredev/sandbox-sdk/vercel";

await using box = await createSandbox(vercel());
await box.files.write("notes/todo.txt", "ship the docs\n");
await box.files.write(".env", "API_KEY=sk-test\n", { mode: 0o600 });
console.log(await box.files.read("notes/todo.txt"));
console.log(await box.files.list("notes"));

Background processes and previews

Vercel routes only to ports declared at creation, up to 15. Previewing another port fails with invalid_argument.

import { createSandbox } from "@opencoredev/sandbox-sdk";
import { vercel } from "@opencoredev/sandbox-sdk/vercel";

await using box = await createSandbox(vercel(), { ports: [5173] });
await box.start("npx vite --port 5173 --host", { name: "vite", ready: { port: 5173 } });
const preview = await box.preview(5173);
console.log(preview.url);

Pause, resume, and snapshots

Vercel sandboxes are persistent by default. pause() stops the session. resume() starts a new one from the saved file system, so files survive but running processes don’t. The SDK marks them failed with exit code 137; restart them by name.

import { createSandbox } from "@opencoredev/sandbox-sdk";
import { vercel } from "@opencoredev/sandbox-sdk/vercel";

await using box = await createSandbox(vercel(), { key: "user:123", ports: [5173] });
const vite = await box.start("npx vite --host 0.0.0.0 --port 5173", {
  name: "vite",
  ready: { port: 5173 },
});
await box.pause();
await box.resume();
await vite.restart();

const { id } = await box.snapshot({ expiresInMs: 7 * 24 * 60 * 60_000 });
await using copy = await createSandbox(vercel(), { from: id });

Any SDK call on a stopped sandbox resumes it. snapshot() also stops the sandbox. expiresInMs must be 0 (never expires) or at least one day; anything else fails with invalid_argument. Without it, Vercel applies snapshotExpiresInMs or its own retention.

Non-persistent sandboxes

Set persistent: false for sandboxes that hold credentials. Vercel then discards the file system whenever the session stops: on timeout, snapshot(), or a native stop(). Such a sandbox can never run again, so the provider has no pause(), connect reports it as "stopped", and further calls fail with not_found. Destroy it and create a new one.

import { createSandbox } from "@opencoredev/sandbox-sdk";
import { vercel } from "@opencoredev/sandbox-sdk/vercel";

const provider = vercel({ persistent: false });
await using box = await createSandbox(provider, { key: "job:42", timeoutMs: 10 * 60_000 });
await box.files.write(".npmrc", "//registry.npmjs.org/:_authToken=npm_xxx\n", { mode: 0o600 });
await box.run("npm ci");

With a key, the next createSandbox call for that key deletes an ended sandbox and creates a fresh one, as Vercel’s own getOrCreate does. snapshot() still works and is the way to keep a template, but it ends the source sandbox.

Size, network, and lifetime

Preset vCPUs Memory
small 1 2048 MiB
medium 2 4096 MiB
large 4 8192 MiB
import { createSandbox } from "@opencoredev/sandbox-sdk";
import { vercel } from "@opencoredev/sandbox-sdk/vercel";

await using box = await createSandbox(vercel(), {
  size: { cpu: 8, memoryMb: 16_384 },
  network: { allow: ["registry.npmjs.org"] },
  timeoutMs: 30 * 60_000,
});
await box.native.extendTimeout(15 * 60_000);

Vercel gives 2048 MiB per vCPU and has no disk setting. An exact size works when memoryMb is 2048 times a whole cpu count and diskGb is unset; anything else fails with unsupported. Your plan caps the count (4 on Hobby, 8 on Pro, 32 on Enterprise). The network allow list blocks every host not on it.

timeoutMs becomes Vercel’s sandbox timeout, which bounds each session, not the sandbox’s whole life. Without it, Vercel stops a session after 5 minutes. A persistent sandbox that times out resumes on the next call with a full new timeoutMs. box.native.extendTimeout(ms) extends only the running session; box.native.update({ timeout }) changes the value for later sessions too. Plans cap a session at 45 minutes on Hobby and 24 hours on Pro and Enterprise. idleTimeoutMs fails with unsupported.

Image, source, and network policy

These options go on vercel(), so they apply to every sandbox that provider creates. Use one provider per configuration.

import { createSandbox } from "@opencoredev/sandbox-sdk";
import { vercel } from "@opencoredev/sandbox-sdk/vercel";

const provider = vercel({
  image: "vercel/sandbox/node:24",
  source: { type: "git", url: "https://github.com/vercel/sandbox.git", depth: 1 },
  region: "fra1",
  networkPolicy: {
    allow: {
      "registry.npmjs.org": [],
      "ai-gateway.vercel.sh": [
        { transform: [{ headers: { authorization: `Bearer ${process.env.AI_GATEWAY_API_KEY}` } }] },
      ],
    },
  },
});
await using box = await createSandbox(provider);
await box.run("ls", { cwd: "/vercel/sandbox" });
  • image pins a Vercel Container Registry image, by tag or @sha256: digest. box.native.image reports the digest you got. The managed images (universal, node:22|24|26, python:3.14, ubuntu, arch) are Ubuntu-based except arch; universal and node:24 run Ubuntu 26.04 today. The legacy runtime values (node22, node24, python3.13) run Amazon Linux 2023. Set one or the other.
  • source clones a git repository (with depth, revision, and username/password for private repos) or unpacks a tarball into /vercel/sandbox, not /workspace. Run commands there with cwd, or clone into /workspace yourself.
  • networkPolicy takes Vercel’s full policy: domain rules, header injection, proxying, and subnet allow and deny lists. Injected headers reach the destination without the sandbox seeing them. Use it or network, not both, or creation fails with invalid_argument.
  • image, runtime, and source apply to fresh sandboxes only. With from, the snapshot supplies the file system.

Configuration

Option Type Default Env var
token string OIDC VERCEL_TOKEN, else VERCEL_OIDC_TOKEN
teamId string VERCEL_TEAM_ID
projectId string VERCEL_PROJECT_ID
persistent boolean true
image string, such as "vercel/sandbox/node:24" vercel/sandbox/universal:latest
runtime "node22", "node24", "node26", "python3.13"
source { type: "git", url, depth?, revision?, username?, password? } or { type: "tarball", url }
region string, such as "fra1" "iad1"
failoverRegions string[]
networkPolicy Vercel NetworkPolicy "allow-all"
networkId string (Secure Compute)
mounts Vercel SandboxMounts
snapshotExpiresInMs number, 0 or at least 86_400_000 Vercel’s
keepLastSnapshots { count, expiresInMs?, deleteEvicted? }
deleteOrphanSnapshots boolean false
fetch typeof fetch globalThis.fetch

A token needs both IDs, or creation fails with auth. Set image or runtime, not both. snapshotExpiresInMs also covers the automatic snapshots that persistence uses, so a paused sandbox loses its files once that snapshot expires. keepLastSnapshots.count runs from 1 to 10. Destroying a sandbox keeps its snapshots until they expire, including the one a paused sandbox saved. deleteOrphanSnapshots makes destroy() delete every snapshot no other sandbox uses instead, including ones you have not restored yet. box.native is the @vercel/sandbox Sandbox object.

Limitations

  • Preview ports must be declared at creation, 15 at most.
  • timeoutMs bounds each session, not the sandbox’s whole life. No idle timeout.
  • A non-persistent sandbox cannot run again once its session stops.
  • At most four labels, or three with a key.
  • Pause and resume end running processes.
  • No terminals.

How it works

  • Vercel enforces unique sandbox names in a project, so concurrent calls with the same key share one sandbox.
  • Your labels become Vercel tags. Vercel allows five; the SDK uses one, and a second for a keyed sandbox.
  • Command timeouts use GNU timeout on a new process group, so the whole tree is killed.
  • files.write with mode sends it in Vercel’s upload, which keeps permission bits and drops setuid, setgid, and sticky. The adapter runs chmod only when one of those is set.

Next steps

Was this page helpful?