-
Notifications
You must be signed in to change notification settings - Fork 9.9k
add docs for keepAlive flag #26121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
add docs for keepAlive flag #26121
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/content/docs/sandbox/configuration/sandbox-options.mdx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| --- | ||
| title: Sandbox options | ||
| pcx_content_type: configuration | ||
| sidebar: | ||
| order: 4 | ||
| --- | ||
|
|
||
| import { TypeScriptExample } from "~/components"; | ||
|
|
||
| Configure sandbox behavior by passing options when creating a sandbox instance with `getSandbox()`. | ||
|
|
||
| ## Available options | ||
|
|
||
| ```ts | ||
| import { getSandbox } from '@cloudflare/sandbox'; | ||
|
|
||
| const sandbox = getSandbox(binding, sandboxId, options?: SandboxOptions); | ||
| ``` | ||
|
|
||
| ### keepAlive | ||
|
|
||
| **Type**: `boolean` | ||
| **Default**: `false` | ||
|
|
||
| Keep the container alive indefinitely by preventing automatic shutdown. When `true`, the container will never auto-timeout and must be explicitly destroyed using `destroy()`. | ||
|
|
||
| <TypeScriptExample> | ||
| ``` | ||
Oxyjun marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // For long-running processes that need the container to stay alive | ||
| const sandbox = getSandbox(env.Sandbox, 'user-123', { | ||
| keepAlive: true | ||
| }); | ||
| // Run your long-running process | ||
| await sandbox.startProcess('python long_running_script.py'); | ||
| // Important: Must explicitly destroy when done | ||
| try { | ||
| // Your work here | ||
| } finally { | ||
| await sandbox.destroy(); // Required to prevent containers running indefinitely | ||
| } | ||
| ``` | ||
| </TypeScriptExample> | ||
|
|
||
| :::caution[Resource management with keepAlive] | ||
| 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. | ||
Oxyjun marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ::: | ||
|
|
||
| ## When to use keepAlive | ||
|
|
||
| Use `keepAlive: true` for: | ||
|
|
||
| - **Long-running builds** - CI/CD pipelines that may have idle periods between steps | ||
| - **Batch processing** - Jobs that process data in waves with gaps between batches | ||
| - **Monitoring tasks** - Processes that periodically check external services | ||
| - **Interactive sessions** - User-driven workflows where the container should remain available | ||
|
|
||
| By default, containers automatically shut down after 10 minutes of inactivity. The `keepAlive` option prevents this automatic shutdown. | ||
|
|
||
| ## Related resources | ||
|
|
||
| - [Background processes guide](/sandbox/guides/background-processes/) - Using keepAlive with long-running processes | ||
Oxyjun marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - [Sessions API reference](/sandbox/api/sessions/) - Container lifecycle management | ||
| - [Sandboxes concept](/sandbox/concepts/sandboxes/) - Understanding sandbox lifecycle | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.