Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/content/docs/sandbox/api/lifecycle.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,18 @@ Containers automatically sleep after 10 minutes of inactivity but still count to

---

## Automatic state cleanup

When a sandbox container sleeps or restarts, the Durable Object automatically cleans up stale state to prevent memory leaks:

- Port authentication tokens are cleared
- Session references are reset
- Mount metadata is removed

This ensures that each container restart starts with a clean state. Your persistent data in the container filesystem remains intact across restarts.

---

## Related resources

- [Sandbox lifecycle concept](/sandbox/concepts/sandboxes/) - Understanding container lifecycle and state
Expand Down
10 changes: 10 additions & 0 deletions src/content/docs/sandbox/concepts/containers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ const process = await sandbox.startProcess('node server.js');
// Returns immediately, process runs in background
```

### Memory management

The container runtime includes optimizations for long-running sandboxes with many processes:

- **Active processes** are kept in memory for fast access
- **Completed processes** are persisted to disk (`/tmp/sandbox-internal/processes/`) and freed from memory to prevent unbounded growth
- **Stream listeners** are automatically cleaned up when streaming operations complete or are cancelled

These optimizations ensure stable memory usage even for sandboxes that execute hundreds or thousands of processes over their lifetime. Process history remains queryable after completion via the standard process APIs.

## Network capabilities

**Outbound connections** work:
Expand Down
Loading