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
The sandbox is running and processing requests. Filesystem, processes, and environment variables persist across requests.
31
+
The sandbox container is running and processing requests. All state remains available: files, running processes, shell sessions, and environment variables.
32
32
33
33
### Idle
34
34
35
-
After inactivity, the sandbox may enter idle state. Filesystem state is preserved, but the container may be paused. Next request triggers a warm start.
35
+
After a period of inactivity, the container stops to free resources. When the next request arrives, a fresh container starts. All previous state is lost and the environment resets to its initial state.
36
36
37
37
### Destruction
38
38
@@ -43,19 +43,23 @@ await sandbox.destroy();
43
43
// All files, processes, and state deleted permanently
44
44
```
45
45
46
-
## Persistence
46
+
## Container lifetime and state
47
47
48
-
Between requests to the same sandbox:
48
+
Sandbox state exists only while the container is active. Understanding this is critical for building reliable applications.
49
49
50
-
**What persists**:
51
-
- Files in `/workspace`, `/tmp`, `/home`
52
-
- Background processes (started with `startProcess()`)
53
-
-Code interpreter contexts and variables
54
-
-Environment variables and port exposures
50
+
**While the container is active** (typically minutes to hours of activity):
51
+
- Files written to `/workspace`, `/tmp`, `/home` remain available
52
+
- Background processes continue running
53
+
-Shell sessions maintain their working directory and environment
54
+
-Code interpreter contexts retain variables and imports
55
55
56
-
**What doesn't persist**:
57
-
- Nothing survives `destroy()`
58
-
- Background processes may stop after container restarts (rare)
56
+
**When the container stops** (due to inactivity or explicit destruction):
57
+
- All files are deleted
58
+
- All processes terminate
59
+
- All shell state resets
60
+
- All code interpreter contexts are cleared
61
+
62
+
The next request creates a fresh container with a clean environment.
59
63
60
64
## Naming strategies
61
65
@@ -65,7 +69,7 @@ Between requests to the same sandbox:
Shell state persists: working directory, environment variables, exported variables all carry over between commands.
28
+
Working directory, environment variables, and exported variables carry over between commands. This state resets if the container restarts due to inactivity.
Context state is lost if the container restarts due to inactivity. For critical data, store results outside the sandbox or design your code to reinitialize as needed.
107
+
:::
108
+
105
109
## Handle rich outputs
106
110
107
111
The code interpreter returns multiple output formats:
0 commit comments