Every time you create a new sandbox, you start with a fresh environment. If your setup involves installing dependencies, cloning repositories, or building code, it can take a while. Snapshots let you save that configured state and create new sandboxes from it, skipping the setup entirely.
With snapshots, you:
- Set up your environment once (install dependencies, configure tools)
- Save the configured state as a snapshot
- Launch future sandboxes from that snapshot with everything already in place
Snapshots persist across sessions, so you can reuse them without repeating setup.
Before you begin, make sure you have:
- Vercel CLI installed (
npm install -g vercel) - Node.js 22 or later
- A Vercel project to link your sandbox and generate an OIDC token
Create a new directory and install dependencies:
This installs the SDK, links to your Vercel project, and creates .env.local with authentication credentials.
Create index.ts with the code below. It runs in two modes:
- First run: Create sandbox, install dependencies, take snapshot
- Second run: Create sandbox from snapshot (deps already there)
To measure the speedup you get from snapshots, use the below version. It records the cold-start time on the first run, then prints the warm-start time (and savings) on the second run.
Execute the script twice:
First execution:
Second execution:
With timing comparison enabled:
Call snapshot() on a running sandbox to save its state:
Important: The sandbox stops automatically after snapshotting. You cannot run more commands on it.
Pass the snapshot ID as the source when creating a new sandbox:
- You can create multiple sandboxes from the same snapshot
- Deleting a snapshot does not affect sandboxes already created from it
For more details, see the Snapshotting documentation.
| Scenario | Use |
|---|---|
| Keep sandbox warm between commands | Sandbox.get() |
| Reuse setup across sessions/days | Snapshot |
| Share environment with teammates | Snapshot |
| Survive sandbox timeout | Snapshot |
| Fastest possible reconnect | Sandbox.get() |
- Learn about Sandbox.get() for reconnecting to running sandboxes
- See the Sandbox SDK reference for all available methods