> ## 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 Sandbox

> Create and manage E2B sandboxes for shell execution, file operations, and multi-step processes.

[E2B](https://e2b.dev/?utm_source=neosantara-docs\&utm_medium=referral) Sandbox provides isolated Firecracker microVM environments for running processes, managing files, and executing shell commands. Unlike the E2B Code Interpreter which focuses on Python code execution and visualization, Sandbox gives full control over the runtime environment including package installation, filesystem manipulation, and multi-step execution.

## Access Credentials

```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

<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 provides `E2BTools` with full sandbox mode for running shell commands and managing files.

    ### Library Installation

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

    ### Implementation Example

    ```python icon="python" theme={"theme":{"light":"ayu-dark","dark":"catppuccin-latte"}}
    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()],
        markdown=True,
        show_tool_calls=True,
        instructions=[
            "Use E2B sandbox to run shell commands and manage files.",
            "Show execution output completely."
        ]
    )

    agent.print_response(
        "Create a project-demo directory, initialize a git repo inside it, "
        "create a hello.py file that prints 'Hello Neosantara', then run it."
    )
    ```
  </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 function calling to execute shell commands and file operations in an E2B sandbox. 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
      ```

      ```bash npm icon="js" theme={"theme":{"light":"ayu-dark","dark":"catppuccin-latte"}}
      npm install openai e2b
      ```
    </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 import Sandbox

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

      tools = [
          {
              "type": "function",
              "function": {
                  "name": "run_shell",
                  "description": "Run a shell command in an isolated E2B sandbox.",
                  "parameters": {
                      "type": "object",
                      "properties": {
                          "command": {"type": "string", "description": "Shell command to execute."}
                      },
                      "required": ["command"]
                  }
              }
          },
          {
              "type": "function",
              "function": {
                  "name": "write_file",
                  "description": "Write a file in the E2B sandbox.",
                  "parameters": {
                      "type": "object",
                      "properties": {
                          "path": {"type": "string", "description": "File path in the sandbox."},
                          "content": {"type": "string", "description": "File content."}
                      },
                      "required": ["path", "content"]
                  }
              }
          }
      ]

      messages = [{"role": "user", "content": "Create a requirements.txt file with requests and httpx, then install with pip."}]

      response = client.chat.completions.create(
          model="deepseek-v4.1-flash",
          messages=messages,
          tools=tools,
          tool_choice="auto"
      )

      message = response.choices[0].message
      sandbox = Sandbox(api_key=os.environ["E2B_API_KEY"])

      if message.tool_calls:
          for tool_call in message.tool_calls:
              args = json.loads(tool_call.function.arguments)

              if tool_call.function.name == "run_shell":
                  result = sandbox.commands.run(args["command"])
                  output = result.stdout
              elif tool_call.function.name == "write_file":
                  sandbox.files.write(args["path"], args["content"])
                  output = f"File {args['path']} written."

              messages.append(message)
              messages.append({
                  "role": "tool",
                  "tool_call_id": tool_call.id,
                  "content": output
              })

          final = client.chat.completions.create(
              model="deepseek-v4.1-flash",
              messages=messages
          )
          print(final.choices[0].message.content)

      sandbox.kill()
      ```

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

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

      const tools = [
        {
          type: "function",
          function: {
            name: "run_shell",
            description: "Run a shell command in an isolated E2B sandbox.",
            parameters: {
              type: "object",
              properties: {
                command: { type: "string", description: "Shell command to execute." },
              },
              required: ["command"],
            },
          },
        },
        {
          type: "function",
          function: {
            name: "write_file",
            description: "Write a file in the E2B sandbox.",
            parameters: {
              type: "object",
              properties: {
                path: { type: "string", description: "File path in the sandbox." },
                content: { type: "string", description: "File content." },
              },
              required: ["path", "content"],
            },
          },
        },
      ];

      const messages = [
        { role: "user", content: "Create a requirements.txt file with requests and httpx, then install with pip." },
      ];

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

      const message = response.choices[0].message;
      const sandbox = await Sandbox.create();

      if (message.tool_calls && message.tool_calls.length > 0) {
        for (const toolCall of message.tool_calls) {
          const args = JSON.parse(toolCall.function.arguments);
          let output;

          if (toolCall.function.name === "run_shell") {
            const result = await sandbox.commands.run(args.command);
            output = result.stdout;
          } else if (toolCall.function.name === "write_file") {
            await sandbox.files.write(args.path, args.content);
            output = `File ${args.path} written.`;
          }

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

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

        console.log(final.choices[0].message.content);
      }

      await sandbox.kill();
      ```
    </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 the Anthropic tool use interface with the Neosantara 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
      ```

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

    ### Implementation Example

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

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

      tools = [
          {
              "name": "run_shell",
              "description": "Run a shell command in an isolated E2B sandbox.",
              "input_schema": {
                  "type": "object",
                  "properties": {
                      "command": {"type": "string", "description": "Shell command to execute."}
                  },
                  "required": ["command"]
              }
          }
      ]

      response = client.messages.create(
          model="claude-3-7-sonnet",
          max_tokens=1024,
          tools=tools,
          messages=[{"role": "user", "content": "Check the installed Python and pip versions in the sandbox."}]
      )

      sandbox = Sandbox(api_key=os.environ["E2B_API_KEY"])

      for block in response.content:
          if block.type == "tool_use":
              command = block.input.get("command")
              result = sandbox.commands.run(command)
              print("Output:", result.stdout)

      sandbox.kill()
      ```

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

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

      const tools = [
        {
          name: "run_shell",
          description: "Run a shell command in an isolated E2B sandbox.",
          input_schema: {
            type: "object",
            properties: {
              command: { type: "string", description: "Shell command to execute." },
            },
            required: ["command"],
          },
        },
      ];

      const response = await client.messages.create({
        model: "claude-3-7-sonnet",
        max_tokens: 1024,
        tools,
        messages: [{ role: "user", content: "Check the installed Python and pip versions in the sandbox." }],
      });

      const sandbox = await Sandbox.create();

      for (const block of response.content) {
        if (block.type === "tool_use") {
          const command = block.input.command;
          const result = await sandbox.commands.run(command);
          console.log("Output:", result.stdout);
        }
      }

      await sandbox.kill();
      ```
    </CodeGroup>
  </Tab>
</Tabs>

## Sandbox Capabilities

| Feature           | API                      | Description                               |
| :---------------- | :----------------------- | :---------------------------------------- |
| **Shell command** | `sandbox.commands.run()` | Execute shell commands with stdout/stderr |
| **File write**    | `sandbox.files.write()`  | Write files to the sandbox filesystem     |
| **File read**     | `sandbox.files.read()`   | Read file contents from the sandbox       |
| **File list**     | `sandbox.files.list()`   | List files and directories                |
| **Upload**        | `sandbox.files.write()`  | Upload binary or text content             |
| **Download**      | `sandbox.files.read()`   | Download files from the sandbox           |
| **Timeout**       | `timeout` parameter      | Control maximum execution duration        |

## Next Steps

| Need                                    | Guide                                                                      |
| :-------------------------------------- | :------------------------------------------------------------------------- |
| Python code execution and visualization | [E2B Code Interpreter](/en/integrations/e2b)                               |
| Daytona sandbox with git and filesystem | [Daytona](/en/integrations/daytona)                                        |
| Tool calling on Gateway                 | [Tool Calling Chat Completions](/en/gateway/chat-completions/tool-calling) |
| Supported model catalog                 | [Models & Pricing](/en/gateway/models)                                     |


## Related topics

- [E2B Code Interpreter](/en/integrations/e2b.md)
- [Daytona Sandbox](/en/integrations/daytona.md)
- [Function Calling (Tools)](/en/gateway/chat-completions/tool-calling.md)
- [Model Catalog](/en/gateway/models.md)
