AutoResume handles this automatically: a paused sandbox wakes up when traffic arrives, so your code never has 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 traffictrueis 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.
autoResume: false, resume explicitly with Sandbox.connect().
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. If you call.kill(), the sandbox is permanently deleted and cannot be resumed.