Overview
Timeout management allows you to:- Set an initial timeout when creating a sandbox
- Extend the timeout for running sandboxes
- Automatically destroy sandboxes after the timeout expires
When a timeout expires, the sandbox is automatically destroyed. All data in the sandbox is lost. Make sure to save important data before the timeout expires.
Setting Timeout on Creation
Set a timeout when creating a sandbox:- Python
- JavaScript
Extending Timeout
Extend the timeout for an existing sandbox:- Python
- JavaScript
Common Timeout Values
Use these common timeout values:- Python
- JavaScript
Checking Expiration
Check when a sandbox will expire:- Python
- JavaScript
Extending Before Expiration
Extend timeout before it expires to prevent automatic destruction:- Python
- JavaScript
No Timeout (Indefinite)
Create a sandbox without a timeout (runs until manually killed):- Python
- JavaScript
Complete Example
Here’s a complete example showing timeout management:- Python
- JavaScript
API Direct Access
You can also manage timeouts using direct API calls:Best Practices
1
1. Set Appropriate Initial Timeouts
Set timeouts based on expected task duration. For quick scripts, use shorter timeouts. For long-running tasks, set longer timeouts.
2
2. Monitor Remaining Time
Check expiration time regularly for long-running sandboxes to avoid unexpected destruction.
3
3. Extend Before Expiration
Extend timeouts before they expire to prevent data loss. Consider setting up monitoring to alert when time is running low.
4
4. Save Important Data
Always save important data before timeout expires. Consider downloading files or storing results externally.
5
5. Use No Timeout for Development
For development and debugging, consider creating sandboxes without timeouts, but remember to clean them up manually.
Timeout vs Manual Cleanup
Automatic Timeout
Set
timeout_seconds when creating or use set_timeout() to automatically destroy sandboxes after a specified duration. Best for production workloads.Manual Cleanup
Call
sandbox.kill() when done. Best for development or when you need precise control over when sandboxes are destroyed.Implementation
- SDK: sandbox.set_timeout() - Python SDK method
- CLI - Command-line interface
- API: PUT /v1/sandboxes/:id/timeout - Control Plane API endpoint
Related
- Creating Sandboxes - Set timeout on creation
- Managing Sandbox State - Control sandbox lifecycle
- Connecting to Sandboxes - Connect to existing sandboxes
Next Steps
- Learn about Creating Sandboxes with timeout configuration
- Explore Managing State for lifecycle control
- Review Listing Sandboxes to monitor sandbox status

