Sandbox persistence is now GA
Mirrored from Vercel — AI for archival readability. Support the source by reading on the original site.
2 min read
Vercel Sandboxes now automatically save and restore filesystem state between sessions. Persistence is on by default, meaning no snapshots to manage or state to track manually.
Each sandbox has a durable, customizable name that acts as a unique reference in your project. You can create, retrieve, or resume a sandbox by name. Vercel spins sessions up and down automatically, without interrupting your workflow.
Link to headingCreate a persistent sandbox
When you call Sandbox.create(), persistence is enabled by default:
import { Sandbox } from "@vercel/sandbox";
// Filesystem is snapshotted automaticallyconst sandbox = await Sandbox.create({ name: "my-sandbox" });
await sandbox.runCommand("npm", ["install"]);
await sandbox.stop();Create a sandbox with persistence on by default
Each automatic snapshot consumes snapshot storage, which is billed separately from compute. For ephemeral workloads, opt out of persistence to minimize storage costs:
import { Sandbox } from "@vercel/sandbox";
const sandbox = await Sandbox.create({ persistent: false });
// Or update an existing sandbox.await sandbox.update({ persistent: false });Create an ephemeral sandbox
To opt out of persistence with the CLI, pass --non-persistent to sandbox create. Non-persistent sandboxes discard their filesystem when the session ends.
Link to headingResume a persistent sandbox
Resuming is automatic. Any call on a stopped sandbox, like runCommand() or writeFiles(), starts a new session from the most recent snapshot.
import { Sandbox } from "@vercel/sandbox";
const resumedSandbox = await Sandbox.get({ name: "my-sandbox" });
// Automatically resumes the sandbox.await resumedSandbox.runCommand("npm", ["test"]);Automatically resume a stopped sandbox
Link to headingOther improvements
Sandbox.fork(): Create a new sandbox from an existing oneSandbox.getOrCreate(): Idempotent retrieve-or-create for long-lived sandboxesSandbox.delete(): Permanently delete a sandboxRicher
sandbox.stop(): Returns snapshot metadata plus active-CPU and network-transfer totalsLifecycle hooks:
onCreateandonResumehooks forcreate,get, andgetOrCreateTags: Assign custom properties to sandboxes for multi-tenant tracking
Link to headingGet started
Upgrade to the latest version to create persistent sandboxes by default:
pnpm install @vercel/sandbox@latest # SDKpnpm install -g sandbox@latest # CLI
Learn more about persistent sandboxes in the documentation.
Discussion (0)
Sign in to join the discussion. Free account, 30 seconds — email code or GitHub.
Sign in →No comments yet. Sign in and be the first to say something.