You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Add description to frontmatter
- Link to persistence page for full lifecycle context
- Merge configuration and cleanup sections
- Remove redundant 'Behavior summary' section
- Simplify web server example (remove Flask, files.write, sleep, status logging)
- Replace with single focused example using python3 -m http.server
- Remove unnecessary 'Agent/tool execution' and 'Per-user sandboxes' sections
- Explain getHost() method with link to internet-access docs
- Reduce page from 256 to 84 lines
description: "Automatically resume paused sandboxes when activity arrives — no manual state management needed."
4
5
---
5
6
6
-
Many workloads don't need a sandbox running all the time, but when they do need it, it should just work, whether it was paused or not.
7
+
Many workloads don't need a sandbox running all the time, but when they do need it, it should just work — whether it was paused or not.
7
8
8
-
`AutoResume` handles this automatically: a paused sandbox wakes up when activity arrives, so your code does not have to check or manage sandbox state.
9
-
Configure it through the `lifecycle` object when creating a sandbox.
9
+
`AutoResume` handles this automatically: a paused sandbox wakes up when activity arrives, so your code doesn't have to check or manage sandbox state. AutoResume builds on the sandbox [persistence](/docs/sandbox/persistence) lifecycle.
10
10
11
-
## Configure lifecycle on create
11
+
## Configure AutoResume
12
+
13
+
Set the `lifecycle` object when creating a sandbox to control what happens on timeout and whether paused sandboxes should auto-resume.
12
14
13
15
<CodeGroup>
14
16
```js JavaScript & TypeScript
@@ -35,7 +37,7 @@ sandbox = Sandbox.create(
35
37
```
36
38
</CodeGroup>
37
39
38
-
## Lifecycle options
40
+
###Lifecycle options
39
41
40
42
-`onTimeout` / `on_timeout`
41
43
-`kill` (default): sandbox is terminated when timeout is reached
@@ -45,117 +47,20 @@ sandbox = Sandbox.create(
45
47
-`true`: paused sandboxes auto-resume on activity
46
48
-`true` is valid only when `onTimeout`/`on_timeout` is `pause`
47
49
48
-
## Behavior summary
49
-
50
-
- Default behavior is equivalent to `onTimeout: "kill"` with `autoResume: false`.
51
-
-`onTimeout: "pause"` with `autoResume: false` gives auto-pause without auto-resume.
52
-
-`onTimeout: "pause"` with `autoResume: true` gives auto-pause with auto-resume.
53
-
-[`Sandbox.connect()`](/docs/sandbox/connect) can still be used to resume a paused sandbox manually.
54
-
55
-
If you use `autoResume: false`, resume explicitly with [`Sandbox.connect()`](/docs/sandbox/connect).
56
-
57
-
## Use cases
58
-
59
-
### Web and dev/preview servers
60
-
61
-
Use `onTimeout: "pause"` + `autoResume: true` so inbound traffic can wake a paused sandbox automatically.
AutoResume is persistent — if a sandbox resumes and later times out again, it will pause again automatically. To permanently delete a sandbox, call `.kill()`. A killed sandbox cannot be resumed.
If `autoResume` is `false`, you can still resume a paused sandbox manually with [`Sandbox.connect()`](/docs/sandbox/connect).
140
53
141
-
preview_host = sandbox.get_host(3000)
142
-
print(f"Preview URL: https://{preview_host}")
54
+
## Example: Web server with AutoResume
143
55
144
-
print(f"Status before pause: {sandbox.get_info().state}")
145
-
sandbox.pause()
146
-
print(f"Status after pause: {sandbox.get_info().state}")
147
-
```
148
-
</CodeGroup>
56
+
AutoResume 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.
149
57
150
-
### Agent/tool execution
151
-
152
-
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.
58
+
The following example starts a simple HTTP server and retrieves its public URL. Use [`getHost()`](/docs/sandbox/internet-access#sandbox-public-url) / `get_host()` to get the sandbox's publicly accessible hostname for a given port.
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.
0 commit comments