Skip to content
Merged
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
68 changes: 66 additions & 2 deletions docs/sandbox.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

# Sandbox / Code Execution

Run model-generated code inside an isolated sandbox and get its output back. The API is provider-agnostic; e2b is the first supported backend, talked to directly over HTTPS with no extra SDK dependency.
Expand Down Expand Up @@ -124,11 +127,50 @@ result = await litellm.acode_interpreter_tool(

Behind the scenes the call goes directly to e2b's REST API: `POST api.e2b.app/sandboxes` to create, a streamed NDJSON `POST` to the per-sandbox host on port 49999 to execute, and `DELETE api.e2b.app/sandboxes/{id}` to tear down.

## LiteLLM Proxy: Responses API code interpreter interceptor
## Responses API code interpreter interceptor

Route OpenAI's `code_interpreter` tool to your sandbox instead of OpenAI's container. The client request stays plain Responses API.

### Setup
### SDK

Register the sandbox tool, install the interceptor as a callback, call `litellm.aresponses` with the `code_interpreter` tool unchanged.

```python showLineNumbers title="sandbox_interceptor.py"
import os, litellm
from litellm.sandbox.sandbox_tools import register_sandbox_tools
from litellm.integrations.code_interpreter_interception.handler import (
CodeInterpreterInterceptionLogger,
)

os.environ["E2B_API_KEY"] = "e2b_..."
os.environ["OPENAI_API_KEY"] = "sk-..."

register_sandbox_tools([
{
"sandbox_tool_name": "my-e2b",
"litellm_params": {
"sandbox_provider": "e2b",
"api_key": "os.environ/E2B_API_KEY",
},
}
])

litellm.callbacks = [
CodeInterpreterInterceptionLogger(
enabled_providers=["openai"],
sandbox_tool_name="my-e2b",
)
]

response = await litellm.aresponses(
model="openai/gpt-5",
tools=[{"type": "code_interpreter", "container": {"type": "auto"}}],
input="Product of first 6 primes. Just the number.",
)
print(response.output_text)
```

### Proxy setup

#### 1. Set keys

Expand Down Expand Up @@ -169,6 +211,9 @@ litellm --config /path/to/config.yaml

#### 4. Call `/v1/responses`

<Tabs>
<TabItem value="curl" label="curl">

```bash
curl -s "http://localhost:4000/v1/responses" \
-H "Authorization: Bearer sk-1234" \
Expand All @@ -180,6 +225,25 @@ curl -s "http://localhost:4000/v1/responses" \
}'
```

</TabItem>
<TabItem value="openai" label="OpenAI SDK">

```python
from openai import OpenAI

client = OpenAI(api_key="sk-1234", base_url="http://localhost:4000/v1")

response = client.responses.create(
model="gpt-5",
tools=[{"type": "code_interpreter", "container": {"type": "auto"}}],
input="Product of first 6 primes. Just the number.",
)
print(response.output_text)
```

</TabItem>
</Tabs>

Response contains a `code_interpreter_call` item with a `cntr_*` `container_id` wrapping the e2b sandbox id.

### Notes
Expand Down