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.
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.
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.
How to use
- Install the SDK and get an API key.
pip install e2b-code-interpreter
- 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)
- Get your API key at e2b.dev and set it as
E2B_API_KEYin your environment.
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.
Related on TokRepo
- AI agent tools -- Frameworks and infrastructure for building autonomous AI agents.
- Coding tools -- Developer tools that integrate with AI workflows.
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
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.
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.
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.
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.
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
Related on TokRepo
Source & Thanks
Created by E2B. Licensed under Apache 2.0. e2b-dev/e2b — 11,500+ GitHub stars
Discussion
Related Assets
NAPI-RS — Build Node.js Native Addons in Rust
Write high-performance Node.js native modules in Rust with automatic TypeScript type generation and cross-platform prebuilt binaries.
Mamba — Fast Cross-Platform Package Manager
A drop-in conda replacement written in C++ that resolves environments in seconds instead of minutes.
Plasmo — The Browser Extension Framework
Build, test, and publish browser extensions for Chrome, Firefox, and Edge using React or Vue with hot-reload and automatic manifest generation.