> ## Documentation Index
> Fetch the complete documentation index at: https://docs.neosantara.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# E2B Code Interpreter

> Execute Python code inside isolated E2B sandboxes using Agno, LiteLLM, and OpenAI or Anthropic SDKs.

[E2B](https://e2b.dev/?utm_source=neosantara-docs\&utm_medium=referral) provides isolated, serverless cloud sandboxes powered by Firecracker microVMs for running code generated by AI models. Combining Neosantara with E2B enables models to perform data analysis, mathematical computations, data visualization, and automated script execution safely without threatening host environments.

## Access Credentials

Export your Neosantara and E2B credentials to your system environment variables:

```bash icon="terminal" theme={"theme":{"light":"ayu-dark","dark":"catppuccin-latte"}}
export NEOSANTARA_API_KEY="nsk_..."
export E2B_API_KEY="e2b_..."
```

## Framework and SDK Integration

Select the framework or client SDK you want to use to view the installation command and code example:

<Tabs>
  <Tab title="Agno" icon="https://mintcdn.com/neosantara/uq2XlSQ_dSPDIOXL/images/integrations/agno.svg?fit=max&auto=format&n=uq2XlSQ_dSPDIOXL&q=85&s=c46fcbc2366c9c7a9514dc31c98e64a1" width="120" height="120" data-path="images/integrations/agno.svg">
    [Agno](https://www.agno.com/?utm_source=neosantara-docs\&utm_medium=referral) is the recommended approach. Neosantara is supported natively via `Neosantara`, and Agno provides a prebuilt `E2BTools` package. Agents manage tool calling, sandbox code execution, and response synthesis automatically without manual loop logic.

    ### Library Installation

    ```bash icon="terminal" theme={"theme":{"light":"ayu-dark","dark":"catppuccin-latte"}}
    pip install -U agno e2b-code-interpreter
    ```

    ### Implementation Example

    ```python icon="python" theme={"theme":{"light":"ayu-dark","dark":"catppuccin-latte"}}
    import os
    from agno.agent import Agent
    from agno.models.neosantara import Neosantara
    from agno.tools.e2b import E2BTools

    agent = Agent(
        model=Neosantara(id="deepseek-v4.1-flash"),
        tools=[E2BTools(timeout=600)],
        markdown=True,
        show_tool_calls=True,
        instructions=[
            "Use the E2B sandbox to run and verify Python code.",
            "Present the final computation results and analysis clearly."
        ]
    )

    agent.print_response(
        "Calculate the first 10 Fibonacci numbers and return them in a Python array."
    )
    ```

    ### Data Visualization

    Agents can run data processing packages inside the sandbox environment:

    ```python icon="python" theme={"theme":{"light":"ayu-dark","dark":"catppuccin-latte"}}
    agent.print_response(
        "Simulate latency metrics for 3 gateways: Neosantara 85ms, US Gateway 280ms, and EU Gateway 320ms. "
        "Plot a bar chart with matplotlib and save the file to latency.png."
    )
    ```
  </Tab>

  <Tab title="LiteLLM" icon="https://mintcdn.com/neosantara/uq2XlSQ_dSPDIOXL/images/integrations/litellm.svg?fit=max&auto=format&n=uq2XlSQ_dSPDIOXL&q=85&s=6423ae40eb025e2fbd909430aac616fd" width="512" height="512" data-path="images/integrations/litellm.svg">
    [LiteLLM](https://www.litellm.ai/?utm_source=neosantara-docs\&utm_medium=referral) routes requests to Neosantara natively via the `neosantara/<model>` prefix without manual base URL overrides.

    ### Library Installation

    ```bash icon="terminal" theme={"theme":{"light":"ayu-dark","dark":"catppuccin-latte"}}
    pip install -U litellm e2b-code-interpreter
    ```

    ### Implementation Example

    ```python icon="python" theme={"theme":{"light":"ayu-dark","dark":"catppuccin-latte"}}
    import os
    from litellm import completion
    from e2b_code_interpreter import Sandbox

    response = completion(
        model="neosantara/deepseek-v4.1-flash",
        messages=[
            {"role": "system", "content": "Return only executable Python code without markdown fences."},
            {"role": "user", "content": "Compute square roots for numbers 1 to 5 and print each result."}
        ]
    )

    python_code = response.choices[0].message.content.strip()

    with Sandbox(api_key=os.environ["E2B_API_KEY"]) as sandbox:
        print("Executing in E2B sandbox...")
        execution = sandbox.run_code(python_code)
        
        if execution.error:
            print("Execution error:", execution.error)
        else:
            for log in execution.logs.stdout:
                print("Output:", log)
    ```
  </Tab>

  <Tab title="OpenAI SDK" icon="https://mintcdn.com/neosantara/uq2XlSQ_dSPDIOXL/images/integrations/openai.svg?fit=max&auto=format&n=uq2XlSQ_dSPDIOXL&q=85&s=69e05803e80721ddc2f9fa7933f78012" width="24" height="24" data-path="images/integrations/openai.svg">
    Use standard [OpenAI](https://openai.com/?utm_source=neosantara-docs\&utm_medium=referral) function calling schemas to execute code within E2B sandboxes. Available for Python and Node.js.

    ### Library Installation

    <CodeGroup>
      ```bash pip icon="python" theme={"theme":{"light":"ayu-dark","dark":"catppuccin-latte"}}
      pip install -U openai e2b-code-interpreter
      ```

      ```bash npm icon="js" theme={"theme":{"light":"ayu-dark","dark":"catppuccin-latte"}}
      npm install openai @e2b/code-interpreter
      ```
    </CodeGroup>

    ### Implementation Example

    <CodeGroup>
      ```python Python icon="python" theme={"theme":{"light":"ayu-dark","dark":"catppuccin-latte"}}
      import os
      import json
      from openai import OpenAI
      from e2b_code_interpreter import Sandbox

      client = OpenAI(
          base_url="https://api.neosantara.xyz/v1",
          api_key=os.environ["NEOSANTARA_API_KEY"]
      )

      tools = [{
          "type": "function",
          "function": {
              "name": "run_python_code",
              "description": "Execute Python code inside an isolated E2B sandbox.",
              "parameters": {
                  "type": "object",
                  "properties": {
                      "code": {"type": "string", "description": "The Python code to execute."}
                  },
                  "required": ["code"]
              }
          }
      }]

      messages = [{"role": "user", "content": "Calculate the factorial of 8 using Python."}]
      response = client.chat.completions.create(
          model="deepseek-v4.1-flash",
          messages=messages,
          tools=tools,
          tool_choice="auto"
      )

      message = response.choices[0].message

      if message.tool_calls:
          tool_call = message.tool_calls[0]
          args = json.loads(tool_call.function.arguments)
          
          with Sandbox(api_key=os.environ["E2B_API_KEY"]) as sandbox:
              exec_result = sandbox.run_code(args["code"])
              output_text = "\n".join(exec_result.logs.stdout)
          
          messages.append(message)
          messages.append({
              "role": "tool",
              "tool_call_id": tool_call.id,
              "content": output_text
          })
          
          final_response = client.chat.completions.create(
              model="deepseek-v4.1-flash",
              messages=messages
          )
          print(final_response.choices[0].message.content)
      ```

      ```javascript Node.js icon="js" theme={"theme":{"light":"ayu-dark","dark":"catppuccin-latte"}}
      import OpenAI from "openai";
      import { Sandbox } from "@e2b/code-interpreter";

      const client = new OpenAI({
        baseURL: "https://api.neosantara.xyz/v1",
        apiKey: process.env.NEOSANTARA_API_KEY,
      });

      const tools = [
        {
          type: "function",
          function: {
            name: "run_python_code",
            description: "Execute Python code inside an isolated E2B sandbox.",
            parameters: {
              type: "object",
              properties: {
                code: { type: "string", description: "The Python code to execute." },
              },
              required: ["code"],
            },
          },
        },
      ];

      const messages = [{ role: "user", content: "Calculate the factorial of 8 using Python." }];

      const response = await client.chat.completions.create({
        model: "deepseek-v4.1-flash",
        messages,
        tools,
        tool_choice: "auto",
      });

      const message = response.choices[0].message;

      if (message.tool_calls && message.tool_calls.length > 0) {
        const toolCall = message.tool_calls[0];
        const args = JSON.parse(toolCall.function.arguments);

        const sandbox = await Sandbox.create();
        const execution = await sandbox.runCode(args.code);
        const outputText = execution.logs.stdout.join("\n");

        messages.push(message);
        messages.push({
          role: "tool",
          tool_call_id: toolCall.id,
          content: outputText,
        });

        const finalResponse = await client.chat.completions.create({
          model: "deepseek-v4.1-flash",
          messages,
        });

        console.log(finalResponse.choices[0].message.content);
      }
      ```
    </CodeGroup>
  </Tab>

  <Tab title="Anthropic SDK" icon="https://mintcdn.com/neosantara/uq2XlSQ_dSPDIOXL/images/integrations/claude.svg?fit=max&auto=format&n=uq2XlSQ_dSPDIOXL&q=85&s=5f0be7b8eabc64ce5a9097ebc400b6b2" width="24" height="24" data-path="images/integrations/claude.svg">
    Use native [Anthropic](https://www.anthropic.com/?utm_source=neosantara-docs\&utm_medium=referral) tool schemas against the Neosantara Anthropic endpoint. Available for Python and Node.js.

    ### Library Installation

    <CodeGroup>
      ```bash pip icon="python" theme={"theme":{"light":"ayu-dark","dark":"catppuccin-latte"}}
      pip install -U anthropic e2b-code-interpreter
      ```

      ```bash npm icon="js" theme={"theme":{"light":"ayu-dark","dark":"catppuccin-latte"}}
      npm install @anthropic-ai/sdk @e2b/code-interpreter
      ```
    </CodeGroup>

    ### Implementation Example

    <CodeGroup>
      ```python Python icon="python" theme={"theme":{"light":"ayu-dark","dark":"catppuccin-latte"}}
      import os
      from anthropic import Anthropic
      from e2b_code_interpreter import Sandbox

      client = Anthropic(
          base_url="https://api.neosantara.xyz/anthropic",
          api_key=os.environ["NEOSANTARA_API_KEY"]
      )

      tools = [{
          "name": "run_python_code",
          "description": "Execute Python code inside an isolated E2B sandbox.",
          "input_schema": {
              "type": "object",
              "properties": {
                  "code": {"type": "string", "description": "Python code to execute."}
              },
              "required": ["code"]
          }
      }]

      response = client.messages.create(
          model="claude-3-7-sonnet",
          max_tokens=1024,
          tools=tools,
          messages=[{"role": "user", "content": "Compute 2 to the power of 16 in Python."}]
      )

      for block in response.content:
          if block.type == "tool_use":
              code_to_run = block.input.get("code")
              with Sandbox(api_key=os.environ["E2B_API_KEY"]) as sandbox:
                  res = sandbox.run_code(code_to_run)
                  print("E2B Output:", res.logs.stdout)
      ```

      ```javascript Node.js icon="js" theme={"theme":{"light":"ayu-dark","dark":"catppuccin-latte"}}
      import Anthropic from "@anthropic-ai/sdk";
      import { Sandbox } from "@e2b/code-interpreter";

      const client = new Anthropic({
        baseURL: "https://api.neosantara.xyz/anthropic",
        apiKey: process.env.NEOSANTARA_API_KEY,
      });

      const tools = [
        {
          name: "run_python_code",
          description: "Execute Python code inside an isolated E2B sandbox.",
          input_schema: {
            type: "object",
            properties: {
              code: { type: "string", description: "Python code to execute." },
            },
            required: ["code"],
          },
        },
      ];

      const response = await client.messages.create({
        model: "claude-3-7-sonnet",
        max_tokens=1024,
        tools,
        messages: [{ role: "user", content: "Compute 2 to the power of 16 in Python." }],
      });

      for (const block of response.content) {
        if (block.type === "tool_use") {
          const codeToRun = block.input.code;
          const sandbox = await Sandbox.create();
          const res = await sandbox.runCode(codeToRun);
          console.log("E2B Output:", res.logs.stdout);
        }
      }
      ```
    </CodeGroup>
  </Tab>
</Tabs>

## Comparison Matrix

| Framework         | Tool Handling                | Endpoint Configuration            | Best For                                                                           |
| :---------------- | :--------------------------- | :-------------------------------- | :--------------------------------------------------------------------------------- |
| **Agno**          | Automatic via `E2BTools`     | Automatic via `Neosantara`        | Autonomous agents without writing boilerplate code extractors or execution loops.  |
| **LiteLLM**       | Direct sandbox execution     | Automatic via `neosantara` prefix | Multi-provider routing or existing proxy infrastructure.                           |
| **OpenAI SDK**    | Manual function calling loop | Manual via `base_url` parameter   | Granular tool-calling loop control on standard OpenAI stacks in Python or Node.js. |
| **Anthropic SDK** | Manual tool use loop         | Manual via `base_url` parameter   | Claude model pipelines using native Anthropic schemas in Python or Node.js.        |

## Next Steps

| Goal                     | Guide                                                                      |
| :----------------------- | :------------------------------------------------------------------------- |
| Agno framework guide     | [Agno Documentation](/en/integrations/agno)                                |
| LiteLLM proxy guide      | [LiteLLM Documentation](/en/integrations/litellm)                          |
| Gateway tool calling     | [Chat Completions Tool Calling](/en/gateway/chat-completions/tool-calling) |
| Supported models catalog | [Model Catalog & Pricing](/en/gateway/models)                              |


## Related topics

- [Agno](/en/integrations/agno.md)
- [LiteLLM](/en/integrations/litellm.md)
- [Function Calling (Tools)](/en/gateway/chat-completions/tool-calling.md)
- [Model Catalog](/en/gateway/models.md)
