Configure
When creating a sandbox, pass alifecycle configuration. This controls timeout behavior and whether a paused sandbox can wake automatically.
Lifecycle options
Thelifecycle setting supports these fields:
| Setting | Option | Meaning |
|---|---|---|
onTimeout (JS) / on_timeout (Python) | "kill" | Default behavior. The sandbox is removed after its timeout. |
onTimeout (JS) / on_timeout (Python) | "pause" | The sandbox is paused after the timeout instead of being deleted. |
autoResume (JS) / auto_resume (Python) | false | Default behavior. Paused sandboxes stay paused until resumed manually. |
autoResume (JS) / auto_resume (Python) | true | Paused sandboxes restart when supported activity arrives. This requires timeout behavior to be "pause". |
Sandbox.connect().
Auto-pause
By default, a sandbox is killed when its timeout expires. To keep the state instead, set theon_timeout option in lifecycle behavior to pause on timeout.
Auto-resume
Auto-resume can wake a paused sandbox when supported activity arrives. This works only when the sandbox is configured to pause on timeout.Timeout after auto-resume
After an automatic resume, the sandbox receives a timeout of at least five minutes. If the original timeout was longer than five minutes, the longer original value is reused. The timeout timer starts when the sandbox resumes, not when it was originally created. Example with a two-minute timeout:- The sandbox runs for two minutes and then pauses.
- New activity reaches the sandbox, causing it to resume.
- The resumed sandbox receives a five-minute timeout because that is the minimum.
- If nothing resets the timer, the sandbox pauses again after five minutes.
- The sandbox resumes with a one-hour timeout, because the original timeout is longer than the five-minute minimum.
You can update the timeout after resuming by using
setTimeout() in JavaScript or set_timeout() in Python.What counts as activity
Auto-resume can be triggered by SDK actions and HTTP traffic. Supported examples include:sandbox.commands.run(...)sandbox.files.read(...)sandbox.files.write(...)- Visiting a tunneled application URL
- Sending requests to a service running inside the sandbox
Sandbox.connect() first.
SDK example: pause, then read a file
This example creates a sandbox, writes a file, pauses the sandbox, and then reads the file. The read operation causes the sandbox to resume.Example: Web server with auto-resume
Auto-resume works well for preview environments and web servers. After the sandbox pauses, an incoming HTTP request to the exposed service can wake it. The example below starts a simple Python HTTP server and prints a public preview URL. You can usegetHost() in JavaScript or get_host() in Python to retrieve the public hostname for a port.
Cleanup
Auto-resume remains enabled across repeated resume and pause cycles. Every resume starts a new timeout period, using at least five minutes or the longer original timeout. After the sandbox resumes, clients should reconnect to any services they were using. Existing HTTP, WebSocket, database, and terminal connections do not stay open while the sandbox is paused. You can call.kill() to delete the sandbox permanently. After that, it cannot be resumed.