Sandbox options
Configure sandbox behavior by passing options when creating a sandbox instance with getSandbox().
import { getSandbox } from '@cloudflare/sandbox';
const sandbox = getSandbox(binding, sandboxId, options?: SandboxOptions);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().
// For long-running processes that need the container to stay aliveconst sandbox = getSandbox(env.Sandbox, "user-123", { keepAlive: true,});
// Run your long-running processawait sandbox.startProcess("python long_running_script.py");
// Important: Must explicitly destroy when donetry { // Your work here} finally { await sandbox.destroy(); // Required to prevent containers running indefinitely}// For long-running processes that need the container to stay aliveconst sandbox = getSandbox(env.Sandbox, 'user-123', { keepAlive: true});
// Run your long-running processawait sandbox.startProcess('python long_running_script.py');
// Important: Must explicitly destroy when donetry { // Your work here} finally { await sandbox.destroy(); // Required to prevent containers running indefinitely}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.
- Background processes guide - Using
keepAlivewith long-running processes - Sessions API reference - Container lifecycle management
- Sandboxes concept - Understanding sandbox lifecycle
Was this helpful?
- Resources
- API
- New to Cloudflare?
- Directory
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- © 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark
-