Skip to content
Closed
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: 10 additions & 2 deletions src/content/docs/sandbox/api/interpreter.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ import { TypeScriptExample } from "~/components";

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

:::note[Context Isolation]
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.
:::

## Methods

### `createCodeContext()`

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

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

### `deleteCodeContext()`

Delete a code execution context and free its resources.
Delete a code execution context and free its dedicated execution resources.

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

:::caution[Context Cleanup]
Always delete contexts when finished to free resources. Each context maintains dedicated execution resources throughout its lifetime.
:::

## Rich Output Formats

Results include: `text`, `html`, `png`, `jpeg`, `svg`, `latex`, `markdown`, `json`, `chart`, `data`
Expand Down
Loading