Prerequisites
Before you begin, make sure you have:- Existing sandbox - A sandbox that was created (see Creating Sandboxes)
- Sandbox object - A
Sandboxinstance connected to your sandbox - Basic understanding - Familiarity with sandbox states and lifecycle
Sandbox States
Sandboxes can be in one of these states:running- Active and ready to execute codestopped- Shut down but can be restartedpaused- Temporarily suspended, can be resumedcreating- Currently being created
When you pause a sandbox, its state is preserved. When you resume it, everything continues from where it left off. Stopped sandboxes lose their runtime state but can be restarted.
Getting Current State
Check the current state of a sandbox:- Python
- JavaScript
Starting a Sandbox
Start a stopped sandbox:- Python
- JavaScript
Stopping a Sandbox
Stop a running sandbox (preserves filesystem but loses runtime state):- Python
- JavaScript
Pausing a Sandbox
Pause a running sandbox (preserves full state including memory):- Python
- JavaScript
Resuming a Sandbox
Resume a paused sandbox (restores full state):- Python
- JavaScript
Complete State Management Example
Here’s a complete example showing all state operations:- Python
- JavaScript
State Transitions
Understanding state transitions helps you manage sandboxes effectively:Pause vs Stop
Pause: Preserves full state (memory, variables, running processes). Fast resume.
Stop: Preserves filesystem only. Runtime state is lost. Requires full restart.
When to Use
Pause: When you need to temporarily suspend work but keep everything in memory.
Stop: When you want to free resources but keep files for later.
Error Handling
Handle state transition errors:- Python
- JavaScript
Best Practices
1
1. Use Pause for Temporary Suspension
Use
pause() when you need to temporarily suspend work but want to preserve all state. Resume is fast and preserves everything.2
2. Use Stop for Resource Management
Use
stop() when you want to free resources but keep the filesystem. Files are preserved, but runtime state is lost.3
3. Check Status Before Operations
Always check the sandbox status before performing operations to avoid errors.
4
4. Handle State Transitions Gracefully
Handle errors when transitioning states - a sandbox might already be in the desired state.
5
5. Clean Up When Done
Always call
kill() when you’re completely done with a sandbox to free resources.Implementation
- SDK: sandbox.start() - Python SDK method
- CLI - Command-line interface
- SDK: sandbox.stop() - Python SDK method
- SDK: sandbox.pause() - Python SDK method
- SDK: sandbox.resume() - Python SDK method
- API: POST /v1/sandboxes/:id/start - Control Plane API endpoint
- API: POST /v1/sandboxes/:id/stop - Control Plane API endpoint
- API: POST /v1/sandboxes/:id/pause - Control Plane API endpoint
- API: POST /v1/sandboxes/:id/resume - Control Plane API endpoint
Related
- Creating Sandboxes - Create new sandboxes
- Connecting to Sandboxes - Connect to existing sandboxes
- Timeout Management - Set sandbox timeouts
Next Steps
- Learn about Timeout Management to control sandbox lifetime
- Review Creating Sandboxes for creating new sandboxes
- Explore Listing Sandboxes to find sandboxes by status

