When you create a sandbox, it continues running until it times out or you explicitly stop it. If your script crashes, your connection drops, or you need to interact with the sandbox from a different process, you can reconnect using Sandbox.get().
This is different from snapshots, which save the sandbox state for later restoration. Sandbox.get() connects to a sandbox that is actively running.
You need the Vercel CLI, Node.js 22+, and a Vercel project to link your sandbox and generate an OIDC token.
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 phases:
- Phase 1: Create a sandbox, persist its ID to disk, and exit
- Phase 2: Load the ID, call Sandbox.get() to reconnect
To measure the speedup from reconnecting vs cold start:
Execute the script twice in quick succession:
First execution:
Second execution (before the 10-minute timeout):
- Script recovery: Reconnect after a crash without losing your running environment
- Multi-process workflows: Access the same sandbox from different scripts or terminals
- CLI tools: Separate sandbox lifecycle management from command execution
- Interactive development: Keep a sandbox warm between debugging sessions
If the sandbox timed out or was stopped, Sandbox.get() throws an error. Always wrap it in a try-catch:
| Operation | Typical Time |
|---|---|
| Create new sandbox | ~2-3s |
Reconnect with Sandbox.get() | ~0.3s |
The ~10x speedup makes Sandbox.get() ideal for keeping sandboxes warm between commands.
| Sandbox.get() | Snapshot.get() | |
|---|---|---|
| Target | Running sandbox | Saved state |
| Requirement | Sandbox must be active | Sandbox can be stopped |
| Persistence | Until timeout | 7 days |
| Best for | Interactive sessions | Reusable templates |
- Learn about snapshots for persisting sandbox state across sessions
- See the Sandbox SDK reference for all available methods