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
Copy file name to clipboardExpand all lines: src/content/docs/sandbox/api/sessions.mdx
+18-54Lines changed: 18 additions & 54 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,42 +13,8 @@ Create isolated execution contexts within a sandbox. Each session maintains its
13
13
Every sandbox has a default session that automatically maintains shell state. Create additional sessions when you need isolated shell contexts for different environments or parallel workflows.
14
14
:::
15
15
16
-
## Sandbox options
17
-
18
-
When creating a sandbox with `getSandbox()`, you can configure its lifecycle behavior:
-`keepAlive` (boolean) - Keep the container alive indefinitely by preventing automatic shutdown. When `true`, the container will never auto-timeout and must be explicitly destroyed using `destroy()`. Default: `false`
29
-
30
-
<TypeScriptExample>
31
-
```
32
-
// For long-running processes that need the container to stay alive
await sandbox.destroy(); // Required to prevent resource leaks
45
-
}
46
-
47
-
````
48
-
</TypeScriptExample>
49
-
50
-
:::caution[Resource management with keepAlive]
51
-
When `keepAlive: true` is set, containers will not automatically timeout and must be explicitly destroyed using `destroy()` to prevent resource leaks and avoid counting toward account limits indefinitely.
16
+
:::note
17
+
For sandbox-level configuration options like `keepAlive`, see the [Sandbox options configuration](/sandbox/configuration/sandbox-options/).
Containers automatically sleep after 10 minutes of inactivity, but still count toward account limits. Use `destroy()` to immediately free up resources.
162
128
163
-
**Important**: When using `keepAlive: true`, containers will not automatically timeout, so calling `destroy()` is **required** to prevent resource leaks.
129
+
**Important**: When using [`keepAlive: true`](/sandbox/configuration/sandbox-options/#keepalive), containers will not automatically timeout, so calling `destroy()` is **required** to prevent containers running indefinitely.
164
130
:::
165
131
166
132
<TypeScriptExample>
167
133
```
168
134
async function executeCode(code: string): Promise<string> {
Keep the container alive indefinitely by preventing automatic shutdown. When `true`, the container will never auto-timeout and must be explicitly destroyed using `destroy()`.
26
+
27
+
<TypeScriptExample>
28
+
```
29
+
// For long-running processes that need the container to stay alive
await sandbox.destroy(); // Required to prevent containers running indefinitely
42
+
}
43
+
```
44
+
</TypeScriptExample>
45
+
46
+
:::caution[Resource management with keepAlive]
47
+
When `keepAlive: true` is set, containers will not automatically timeout and must be explicitly destroyed using `destroy()` to prevent containers running indefinitely and counting toward your account limits.
48
+
:::
49
+
50
+
## When to use keepAlive
51
+
52
+
Use `keepAlive: true` for:
53
+
54
+
-**Long-running builds** - CI/CD pipelines that may have idle periods between steps
55
+
-**Batch processing** - Jobs that process data in waves with gaps between batches
56
+
-**Monitoring tasks** - Processes that periodically check external services
57
+
-**Interactive sessions** - User-driven workflows where the container should remain available
58
+
59
+
By default, containers automatically shut down after 10 minutes of inactivity. The `keepAlive` option prevents this automatic shutdown.
60
+
61
+
## Related resources
62
+
63
+
-[Background processes guide](/sandbox/guides/background-processes/) - Using keepAlive with long-running processes
64
+
-[Sessions API reference](/sandbox/api/sessions/) - Container lifecycle management
0 commit comments