Configure
Set thelifecycle object when creating a sandbox to control what happens on timeout and whether paused sandboxes should auto-resume.
Lifecycle options
Thelifecycle object accepts the following options:
| Setting | Option | Description |
|---|---|---|
onTimeout (JavaScript) / on_timeout (Python) | "kill" | (default) Sandbox is terminated when timeout is reached |
"pause" | Sandbox is paused when timeout is reached | |
autoResume (JavaScript) / auto_resume (Python) | false | (default) Paused sandboxes do not auto-resume |
true | Paused sandboxes auto-resume on activity. Valid only when onTimeout / on_timeout is set to "pause" |
lifecycle.autoResume / lifecycle.auto_resume is falsy or unset, you can still resume a paused sandbox manually with Sandbox.connect().
Timeout after auto-resume
When a sandbox auto-resumes, it restarts with a 5-minute minimum timeout. If you originally created the sandbox with a longer timeout, that value carries over. The countdown begins from the moment the sandbox resumes, not from when it was first created. For example, if you create a sandbox with a 2-minute timeout:- The sandbox runs for 2 minutes, then pauses.
- Activity arrives and the sandbox auto-resumes.
- A 5-minute timeout starts (the 5-minute minimum applies because the original timeout was shorter).
- If no further activity resets the timeout, the sandbox pauses again after 5 minutes.
You can change the timeout after the sandbox resumes by calling
setTimeout() (JavaScript) / set_timeout() (Python). See Change sandbox timeout during runtime.What counts as activity
Auto-resume is triggered by sandbox activity — both HTTP traffic and SDK operations. That includes:sandbox.commands.run(...)sandbox.files.read(...)sandbox.files.write(...)- Opening a tunneled app URL or sending requests to a service running inside the sandbox
lifecycle.autoResume (JavaScript) / lifecycle.auto_resume (Python) is enabled, the next supported operation resumes it automatically. You do not need to call Sandbox.connect() first.
SDK example: pause, then read a file
The following example writes a file, pauses the sandbox, then reads the file back. The read operation triggers an automatic resume.Example: Web server with auto-resume
Auto-resume is especially useful for web servers and preview environments. When an HTTP request arrives at a paused sandbox, the sandbox wakes up automatically to handle it. The following example starts a simple HTTP server and retrieves its public URL. UsegetHost() (JavaScript) / get_host() (Python) to get the sandbox’s publicly accessible hostname for a given port.
Cleanup
Auto-resume is persistent — if your sandbox resumes and later times out again, it will pause again. Each time the sandbox resumes, it gets a fresh timeout (at least 5 minutes, or longer if the original creation timeout exceeds that) — so the sandbox keeps cycling between running and paused as long as activity arrives. If you call.kill(), the sandbox is permanently deleted and cannot be resumed.