Skip to content

Commit 1512d4c

Browse files
Update Code Interpreter docs for improved context isolation
Documents the fix for code context isolation bug where contexts leaked state after 10 executions. Each context now has dedicated executor resources throughout its lifetime, ensuring complete isolation. Changes: - Add context isolation note explaining dedicated resources - Emphasize isolation guarantees in createCodeContext() - Add cleanup best practice for deleteCodeContext() - Remove implied pool size limitations Related to cloudflare/sandbox-sdk#249 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 0f1dfd7 commit 1512d4c

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/content/docs/sandbox/api/interpreter.mdx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,15 @@ import { TypeScriptExample } from "~/components";
99

1010
Execute Python, JavaScript, and TypeScript code with support for data visualizations, tables, and rich output formats. Contexts maintain state (variables, imports, functions) across executions.
1111

12+
:::note[Context Isolation]
13+
Each code context is fully isolated with dedicated execution resources from creation to deletion. Contexts do not share state with each other, ensuring complete isolation for security and correctness. You can create as many concurrent contexts as needed without pool size limitations.
14+
:::
15+
1216
## Methods
1317

1418
### `createCodeContext()`
1519

16-
Create a persistent execution context for running code.
20+
Create a persistent execution context for running code. Each context receives dedicated execution resources and maintains complete isolation from other contexts.
1721

1822
```ts
1923
const context = await sandbox.createCodeContext(options?: CreateContextOptions): Promise<CodeContext>
@@ -121,7 +125,7 @@ console.log(`Found ${contexts.length} contexts`);
121125

122126
### `deleteCodeContext()`
123127

124-
Delete a code execution context and free its resources.
128+
Delete a code execution context and free its dedicated execution resources.
125129

126130
```ts
127131
await sandbox.deleteCodeContext(contextId: string): Promise<void>
@@ -135,6 +139,10 @@ await sandbox.deleteCodeContext(ctx.id);
135139
```
136140
</TypeScriptExample>
137141

142+
:::caution[Context Cleanup]
143+
Always delete contexts when finished to free resources. Each context maintains dedicated execution resources throughout its lifetime.
144+
:::
145+
138146
## Rich Output Formats
139147

140148
Results include: `text`, `html`, `png`, `jpeg`, `svg`, `latex`, `markdown`, `json`, `chart`, `data`

0 commit comments

Comments
 (0)