Skip to main content
Sandboxes can be configured with automatic timeout values that determine when they are automatically destroyed. This helps manage resources and costs while ensuring sandboxes don’t run indefinitely.

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:
Expected Output:

Extending Timeout

Extend the timeout for an existing sandbox:
Expected Output:
The set_timeout() method sets a new timeout duration from the current time, not from the original expiration. Each call resets the timer.

Common Timeout Values

Use these common timeout values:

Checking Expiration

Check when a sandbox will expire:
Expected Output:

Extending Before Expiration

Extend timeout before it expires to prevent automatic destruction:
Expected Output:

No Timeout (Indefinite)

Create a sandbox without a timeout (runs until manually killed):
Expected Output:

Complete Example

Here’s a complete example showing timeout management:
Expected Output:

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

Next Steps