Table of Contents

E2B

E2B (pronounced “edge-to-backend”) is an open-source infrastructure platform that provides secure, isolated cloud sandboxes for running AI-generated code. Built on Firecracker microVMs (the same technology behind AWS Lambda), E2B enables AI agents to execute arbitrary code safely without risking the host system. With 11,000+ GitHub stars, $21M in Series A funding, and adoption by Fortune 100 companies, it has become the standard for sandboxed code execution in agentic AI systems.

Architecture

E2B's architecture centers on Firecracker microVMs for hardware-level isolation:

Code Interpreter SDK

The Code Interpreter SDK is E2B's primary interface, launching Jupyter servers inside sandboxes for LLMs to execute code:

How Sandboxes Work

  1. CreationSandbox.create() provisions a new Firecracker microVM in under 200ms
  2. Code Executionsandbox.run_code() sends code to the Jupyter kernel inside the sandbox
  3. File Operations — Read, write, and manage files within the sandbox filesystem
  4. Internet Access — Install packages via pip/npm, make API calls, download data
  5. Process Management — Spawn child processes, run shell commands
  6. Teardown — Sandbox destroys automatically on exit or timeout

Key Features

Code Example

from openai import OpenAI
from e2b_code_interpreter import Sandbox
 
# Create OpenAI client for code generation
client = OpenAI()
 
# Define the task
system_prompt = (
    "You are a data analyst. Write Python code to answer questions. "
    "Only output executable code, no explanations."
)
user_prompt = "Generate a bar chart of the top 5 programming languages by popularity in 2025."
 
# Get code from LLM
response = client.chat.completions.create(
    model="gpt-4o",
    messages=[
        {"role": "system", "content": system_prompt},
        {"role": "user", "content": user_prompt},
    ],
)
code = response.choices[0].message.content
 
# Execute in secure E2B sandbox
with Sandbox() as sandbox:
    # Install dependencies
    sandbox.run_code("!pip install matplotlib")
 
    # Run the generated code
    execution = sandbox.run_code(code)
    print("Output:", execution.text)
 
    # Check for errors
    if execution.error:
        print(f"Error: {execution.error.name}: {execution.error.value}")
 
    # Access generated files (e.g., chart images)
    for artifact in execution.results:
        print(f"Generated: {artifact}")

Architecture Diagram

graph TD A["AI Agent (your app)"] <--> B["LLM API (GPT-4o / Claude)"] A -->|E2B SDK| C["E2B Cloud Platform"] C --> D["Firecracker MicroVM"] D --> E["Jupyter Server"] E --> F["Python Kernel (code execution)"] D --> G["Isolated Filesystem"] D --> H["Resource Controls (CPU / RAM / Net)"]

References

See Also