AutoResume handles this automatically: a paused sandbox wakes up when activity arrives, so your code does not have to check or manage sandbox state.
Configure it through the lifecycle object when creating a sandbox.
Configure lifecycle on create
Lifecycle options
onTimeout/on_timeoutkill(default): sandbox is terminated when timeout is reachedpause: sandbox is paused when timeout is reached
autoResume/auto_resumefalse(default): paused sandboxes do not auto-resumetrue: paused sandboxes auto-resume on activitytrueis valid only whenonTimeout/on_timeoutispause
Behavior summary
- Default behavior is equivalent to
onTimeout: "kill"withautoResume: false. onTimeout: "pause"withautoResume: falsegives auto-pause without auto-resume.onTimeout: "pause"withautoResume: truegives auto-pause with auto-resume.Sandbox.connect()can still be used to resume a paused sandbox manually.
autoResume: false, resume explicitly with Sandbox.connect().
Timeout after auto-resume
When a sandbox auto-resumes, it starts a new timeout equal to the original timeout set at creation. 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 10-minute timeout:- The sandbox runs for 10 minutes, then pauses.
- Activity arrives and the sandbox auto-resumes.
- A fresh 10-minute timeout starts.
- If no further activity resets the timeout, the sandbox pauses again after 10 minutes.
onTimeout: "pause" + autoResume: true) is persistent across pause/resume cycles.
You can change the timeout after the sandbox resumes by calling
setTimeout/set_timeout. See Change sandbox timeout during runtime.What counts as activity
Auto-resume is triggered by the sandbox activity - that’s both HTTP traffic and controlling the sandbox from the SDK. That includes SDK operations like:sandbox.commands.run(...)sandbox.files.read(...)sandbox.files.write(...)- opening a tunneled app URL or sending requests to a service running inside the sandbox
autoResume 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
Use cases
Web and dev/preview servers
UseonTimeout: "pause" + autoResume: true so inbound traffic can wake a paused sandbox automatically.
This works for both:
- Basic web/API servers
- Dev or preview servers you open occasionally
Agent/tool execution
For queued tasks or tool calls, create once and keep using the same sandbox handle. If it is paused, it will auto-resume when you run the next command.Per-user sandboxes
For multi-tenant apps, keep a map of sandbox IDs by user. On each request, connect to the user’s existing sandbox (which auto-resumes if paused) or create a new one.Cleanup
Auto-resume is persistent, meaning if your sandbox resumes and later times out again, it will pause again. Each time the sandbox resumes, the original timeout resets — 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.