---
title: "E2B MCP: Sandboxed Code Execution"
source: https://docs.autohand.ai/guides/mcp/e2b-sandbox
---

# E2B MCP: Sandboxed Code Execution

Let Autohand run code without risk. E2B provides cloud sandboxes where the agent can execute Python, JavaScript, and shell commands in isolated environments that cannot affect your local machine.

## What E2B does

[E2B MCP](https://github.com/e2b-dev/mcp-server) gives Autohand access to secure cloud sandboxes. Each sandbox is a lightweight virtual machine with its own filesystem, network, and process space. The agent can install packages, run scripts, start servers, and execute arbitrary code without any risk to your development environment.

This is useful when you want the agent to test code before writing it to your project, run data processing scripts on untrusted data, or experiment with packages you have not installed locally.

## Setup

E2B MCP uses the stdio transport. Get an API key from [e2b.dev](https://e2b.dev) (free tier includes 100 sandbox hours per month).

``` bash
# Add E2B MCP
autohand mcp add e2b npx -y @e2b/mcp-server

# Set your API key
export E2B_API_KEY="your-e2b-api-key"

# Verify connection
autohand mcp list
```

Configuration in `~/.autohand/config.json`:

``` json
{
  "mcp": {
    "servers": [
      {
        "name": "e2b",
        "transport": "stdio",
        "command": "npx",
        "args": ["-y", "@e2b/mcp-server"],
        "env": {
          "E2B_API_KEY": "your-e2b-api-key"
        },
        "autoConnect": true
      }
    ]
  }
}
```

## Usage examples

### Test code before committing

``` bash
# Let the agent prototype and verify in a sandbox first
autohand --prompt "Write a Python script that parses CSV files and generates summary statistics. Test it with sample data before saving to my project."

# The agent writes code, runs it in E2B, verifies the output, then saves
# the working version to your project
```

### Install and test packages safely

``` bash
# Try out a new package without installing locally
autohand --prompt "Try the 'polars' Python library for data analysis. Load this CSV and compare performance with pandas: data/sales.csv"

# Installs polars in the sandbox, runs benchmarks, reports results
```

### Run data processing pipelines

``` bash
# Process data in isolation
autohand --prompt "Write a script to clean and normalize the customer data in data/raw.json. Run it in a sandbox and save the cleaned output."

# Processes data in the sandbox, validates results, then writes output
```

### Debug with full isolation

``` bash
# Reproduce and fix a bug in a clean environment
autohand --prompt "This function crashes on certain inputs. Set up a clean environment in a sandbox, reproduce the bug, and fix it: src/utils/parser.ts"

# Creates a clean sandbox, installs dependencies, runs the failing case,
# iterates on a fix until the tests pass
```

## When to use E2B vs local execution

| Scenario | Local | E2B Sandbox |
|---|---|---|
| Quick edits to your project files | Best | Overkill |
| Running your test suite | Best | If tests need isolation |
| Trying unfamiliar packages | Risky | Best |
| Processing untrusted data | Risky | Best |
| Prototyping new algorithms | Fine | Best |
| Running resource-heavy computations | Slow | Best |

## E2B with Yolo Mode

E2B sandboxes are naturally safe since they cannot modify your local files. Combine E2B with Yolo Mode for fully autonomous experimentation:

``` bash
# Let the agent experiment freely in sandboxes
autohand --yolo true --prompt "Benchmark five different JSON parsing libraries in Python. Install each one, run the same test suite, and give me a comparison table."

# The agent creates sandboxes, installs packages, runs tests, all without
# permission prompts since everything happens in isolation
```

## Tips

-   E2B sandboxes persist for the duration of your session. The agent can install packages once and run multiple scripts without reinstalling.
-   The free tier gives you 100 sandbox hours per month, which covers most development workflows.
-   Sandboxes have network access, so the agent can fetch remote data, call APIs, and download dependencies.
-   For production data processing, tell the agent to save results locally after verifying them in the sandbox.
-   E2B supports custom sandbox templates. If you need specific system packages pre-installed, create a template on the E2B dashboard.