ScriptsMar 31, 2026·2 min read

E2B — Secure Sandboxes for AI Code Execution

Open-source cloud sandboxes for AI agents to execute code safely. Isolated Linux environments with filesystem, networking, and process control. 11.5K+ stars.

TL;DR
E2B spins up isolated Linux sandboxes in milliseconds so AI agents can execute arbitrary code without risking your host system.
§01

What it is

E2B provides open-source, secure cloud sandboxes for AI agents to execute code safely. Each sandbox is an isolated Linux environment with its own filesystem, networking, and process control, spun up in roughly 150 milliseconds. The primary use case is letting LLM-powered agents run generated code without risking the host system or leaking sensitive data.

It is designed for developers building AI coding assistants, data analysis agents, or any application where an LLM needs to run untrusted code in a controlled environment.

§02

How it saves time or tokens

Without E2B, developers build custom Docker-based sandboxing, handle timeout management, and deal with resource limits manually. E2B abstracts all of this behind a Python or TypeScript SDK. Sandboxes start in under a second and clean up automatically. The code interpreter SDK provides a pre-configured Python environment with common data science libraries already installed, removing setup overhead for analytics use cases.

§03

How to use

  1. Install the SDK and get an API key.
pip install e2b-code-interpreter
  1. Run code in a sandbox.
from e2b_code_interpreter import Sandbox

with Sandbox() as sandbox:
    execution = sandbox.run_code("print('Hello from sandbox!')")
    print(execution.text)
  1. Get your API key at e2b.dev and set it as E2B_API_KEY in your environment.
§04

Example

Running a data analysis task:

from e2b_code_interpreter import Sandbox

code = '''
import pandas as pd
import numpy as np

df = pd.DataFrame({
    'product': ['A', 'B', 'C'] * 100,
    'revenue': np.random.uniform(100, 1000, 300)
})
print(df.groupby('product')['revenue'].agg(['mean', 'sum']).round(2))
'''

with Sandbox() as sandbox:
    result = sandbox.run_code(code)
    print(result.text)

The sandbox has pandas, numpy, matplotlib, and other common libraries pre-installed.

§05

Related on TokRepo

  • AI agent tools -- Frameworks and infrastructure for building autonomous AI agents.
  • Coding tools -- Developer tools that integrate with AI workflows.
§06

Common pitfalls

  • Sandbox instances have resource limits (CPU, memory, execution time). Long-running computations may be terminated. Check the plan limits on e2b.dev.
  • The free tier has a limited number of sandbox hours per month. Monitor usage to avoid unexpected throttling.
  • Network access from sandboxes is enabled by default. If your use case requires full isolation, configure the sandbox to disable outbound networking.

Frequently Asked Questions

Is E2B open source?+

Yes. The E2B SDK and sandbox runtime are open source under the Apache 2.0 license. The cloud infrastructure that runs the sandboxes is a managed service. You can also self-host the sandbox runtime using the open-source components.

How fast do E2B sandboxes start?+

E2B sandboxes start in approximately 150 milliseconds. This is fast enough for interactive use cases where an AI agent needs to execute code and return results within a conversation turn.

What languages can run inside an E2B sandbox?+

The code interpreter sandbox comes with Python pre-installed. You can also create custom sandbox templates with any language runtime -- Node.js, Go, Rust, or anything that runs on Linux. Custom templates are defined via Dockerfiles.

How does E2B handle security?+

Each sandbox runs in an isolated microVM with its own kernel, filesystem, and network namespace. There is no shared state between sandboxes. If a sandbox executes malicious code, it cannot affect other sandboxes or the host.

Can I use E2B with LangChain or other agent frameworks?+

Yes. E2B provides integrations for LangChain, CrewAI, and OpenAI function calling. The SDK returns structured output that agent frameworks can parse and use as tool results.

Citations (3)
  • E2B GitHub— Open-source secure cloud sandboxes with isolated Linux environments
  • E2B Documentation— Sandboxes start in approximately 150ms using microVMs
  • E2B SDK README— Integrations with LangChain, CrewAI, and OpenAI
🙏

Source & Thanks

Created by E2B. Licensed under Apache 2.0. e2b-dev/e2b — 11,500+ GitHub stars

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets