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.
Copy link to headingPrerequisites
You need the Vercel CLI, Node.js 22+, and a Vercel project to link your sandbox and generate an OIDC token.
Copy link to heading1. Set up the project
This installs the SDK, links to your Vercel project, and creates .env.local with authentication credentials.
Copy link to heading2. Write the script
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
Copy link to headingWith timing comparison
To measure the speedup from reconnecting vs cold start:
Copy link to heading3. Test it out
Execute the script twice in quick succession:
First execution:
Second execution (before the 10-minute timeout):
Copy link to headingUse cases for Sandbox.get()
- 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
Copy link to headingHandling expired sandboxes
If the sandbox timed out or was stopped, Sandbox.get() throws an error. Always wrap it in a try-catch:
Copy link to headingPerformance
| 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.
Copy link to headingKey differences: Sandbox.get() vs Snapshot.get()
| 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 |
Copy link to headingNext steps
- Learn about snapshots for persisting sandbox state across sessions
- See the Sandbox SDK reference for all available methods