Skip to content
Docs

Understanding Sandboxes

Vercel Sandboxes provide on-demand, isolated compute environments for running untrusted code, testing applications, executing AI-generated scripts, and more. Sandboxes are persistent by default: when a sandbox stops, Vercel automatically snapshots its filesystem, and the sandbox configuration is preserved across sessions, so both are restored the next time you resume.

A sandbox is an isolated Linux environment that you create programmatically with the SDK or CLI. Think of it as a secure virtual machine that:

  • Boots from a Vercel Managed Image, a custom VCR image, or a saved snapshot
  • Uses Ubuntu, Arch Linux, or any other Linux distribution you need
  • Has network access for installing packages and making API calls
  • Automatically stops after a configurable timeout
  • Provides full root access to install any package or binary

Each sandbox includes configurable isolation:

  • Filesystem access: A dedicated private filesystem. With persistence enabled (the default), the filesystem is automatically snapshotted on stop and restored when the sandbox resumes. The sandbox configuration is preserved across sessions and reapplied on resume.
  • Process isolation: Kernel-level isolation ensures code cannot see or access processes in other sandboxes.
  • Network isolation: Each sandbox has its own network namespace with controlled outbound access.

Unlike Docker containers, each sandbox runs in its own Firecracker microVM with a dedicated kernel. This provides stronger isolation than container-based solutions, which makes sandboxes ideal for running untrusted code.

AspectDocker containersVercel Sandboxes
IsolationShares host kernel; relies on namespaces and cgroupsDedicated kernel per sandbox; full VM isolation
SecuritySuitable for trusted code; container escapes are possibleDesigned for untrusted code; microVM boundary prevents escapes
Startup timeSub-secondMilliseconds (Firecracker optimized for fast boot)
Use casePackaging and deploying applicationsRunning arbitrary, untrusted code safely

If you already use Docker images to define your environment, store the image in Vercel Container Registry (VCR) and create the sandbox with a custom image. See Images. You can also install packages with your system's package manager, or take a snapshot after setup when a Docker image is not needed.

When you call Sandbox.create(), Vercel provisions a Firecracker microVM on its infrastructure. This microVM boots an Ubuntu 26.04 image, a custom image from VCR, or a saved snapshot.

The sandbox runs on Vercel's infrastructure, so you don't need to manage servers, scale capacity, or worry about availability. Sandboxes provision in the iad1 region by default. You can choose a different region per sandbox or set a project default. See Regions.

Here's what happens during the lifecycle:

  1. Provisioning: Vercel allocates compute resources and boots the microVM. Resuming from a snapshot is even faster than starting a fresh sandbox.
  2. Running: Your code executes inside a session. A session is a single running VM instance inside a sandbox. You can run commands, install packages, start servers, and interact with the filesystem.
  3. Stopping: When the timeout expires or you call stop(), the session shuts down. For persistent sandboxes (the default), Vercel automatically snapshots the filesystem so the next session resumes from the same state. For non-persistent sandboxes, the filesystem is discarded.
  4. Resuming: The next SDK call (such as runCommand or writeFiles) on a stopped persistent sandbox starts a new session from the most recent snapshot. You don't need to resume manually.

For long-term storage of data that doesn't belong in the filesystem, write it to external services like databases or object storage.

When you're ready to use a sandbox, you can either create a new one from scratch or use a saved snapshot of a sandbox you created previously. Using a snapshot is much faster than creating from scratch because it avoids reinstalling dependencies and repeating setup steps.

Think of it like the difference between booting a fresh OS install versus resuming from a saved state. A new sandbox gives you a clean slate; a snapshot gives you a pre-configured environment ready to go.

Sandboxes are identified by a name that is unique within your project. If you don't provide one, the SDK generates a name for you. Use the same name later with Sandbox.get() or Sandbox.getOrCreate() to resume the sandbox.

To create a sandbox, you can use the CLI, the JS SDK, or the Python SDK:

terminal.sh
# Create a sandbox with a random name
sandbox create
 
# Create with an explicit name
sandbox create --name my-sandbox

Once created, you can run commands inside the sandbox. Commands can run in blocking mode (wait for completion) or detached mode (return immediately).

terminal.sh
# Run a command in an existing sandbox (by name)
sandbox exec my-sandbox -- npm install
 
# Run interactively
sandbox exec --interactive --tty my-sandbox -- bash
 
# Run with environment variables
sandbox exec --env DEBUG=true my-sandbox -- npm test

Sandboxes automatically stop after a timeout. The default timeout is 5 minutes, and the maximum applies to each session, not to the sandbox itself. A sandbox spans as many sessions as you resume it for: an agent workspace resumed once a day for a week is one sandbox and seven sessions.

Alternatively, you can stop them manually. stop() resolves once the VM is fully stopped, and returns the final session state. For persistent sandboxes, the resolved value also includes metadata for the snapshot captured during shutdown.

terminal.sh
sandbox stop my-sandbox

You can also stop sandboxes from the Vercel Dashboard by navigating to Observability > Sandboxes and clicking Stop Sandbox.

Snapshots save the current state of a sandbox, including all installed packages and files. Use snapshots to skip setup time on subsequent runs, checkpoint long-running tasks, or share environments with teammates.

See Snapshots for complete documentation on creating, retrieving, and managing snapshots.

Vercel Sandboxes are ideal for features that require secure, on-demand code execution:

PatternWhy use sandboxes?Example
AI code interpreterLLM-generated code can be unpredictable. Sandboxes ensure it runs in isolation.An AI assistant that solves math problems by writing and running Python scripts.
Clean test environmentsStart fresh for every test run to avoid "works on my machine" issues.Running unit tests against a clean OS for every commit.
Reproducible infrastructureShare identical snapshots of environments across teams.A QA team spinning up an exact replica of a customer's environment.
Temporary debuggingSpin up a throwaway environment to inspect issues without risk.Investigating a production issue by replicating the environment.

Sandboxes are not designed to run continuously. They are not suitable for:

  • Permanent hosting: If you need a server that stays up 24/7, use a traditional VM or Vercel Functions.
  • Long-term storage of large datasets: The filesystem persists between sessions of a persistent sandbox, but it isn't a substitute for a database or object store. Push large or shared data to external services.

Vercel Sandboxes are designed for running untrusted code safely. Each sandbox runs in its own Firecracker microVM with a dedicated kernel, enforced resource limits, and controlled network access.

See Sandbox security model for the full security model, including the isolation architecture, hardware side channels, resource limits, network access, and data privacy.

  • Persistent sandboxes: Sandboxes that auto-save state and resume where you left off.
  • Tags: Categorize sandboxes by environment, team, or any other criteria using key-value tags.
  • Drives: Attach persistent filesystem storage to sandboxes and reuse data across sandbox runs.
  • Regions: Choose where your sandboxes run and configure failover regions.
  • Secure Compute: Send a sandbox's public-internet traffic through a network's static IPs, and reach your own VPC over VPC peering.
  • Security model: How the sandbox boundary isolates untrusted code, and what it does and does not cover.
  • Quickstart: Run your first sandbox.
  • Working with Sandbox: Task-oriented guides for common operations.
  • Authentication: Configure SDK authentication.
  • Snapshots: Save and restore sandbox state.
  • JS SDK Reference: Full API documentation for JavaScript and TypeScript.
  • Python SDK Reference: Full API documentation for Python.
  • CLI Reference: Manage sandboxes from the terminal.
  • Examples: Real-world use cases and code samples.
Last updated August 25, 2026

Was this helpful?

supported.