E2B Infrastructure
repository·main·Indexed 22 days ago
https://github.com/e2b-dev/infraBackend foundation for AI code interpreting, providing components to power the E2B platform. Includes documentation for Terraform deployments on major cloud providers, the envd sandbox daemon, Redis Reservation Storage for sandbox management, Nomad Node Pool Autoscaler plugins (nomad-nodepool-apm and nomad-deployment-aware-target), and the Orchestrator for managing sandbox builds and snapshots.
What's inside e2b-dev-infra
- E2B Infrastructure is the open-source foundation that powers the E2B platform, specifically designed for AI code interpreting. While the main e2b-dev/e2b repository provides the SDKs and CLI for managing environments and running AI agents, this repository contains the underlying infrastructure components.
Overview of E2B Infrastructure services
mainThe E2B infrastructure is composed of several specialized services organized into functional layers:
Control Plane
- API (
packages/api): The central REST and gRPC entry point for managing sandboxes, templates, and builds. It uses PostgreSQL for persistent state and Redis for real-time tracking. - Dashboard API (
packages/dashboard-api): Serves the dashboard interface, interacting with PostgreSQL and ClickHouse. - Client Proxy (
packages/client-proxy): Handles routing for sandbox traffic (e.g.,port-sandboxid.domain) by looking up sandbox locations in Redis and forwarding requests to the appropriate orchestrator. - Docker Reverse Proxy (
packages/docker-reverse-proxy): Manages Docker-related traffic.
Data Plane & Execution
- Orchestrator (
packages/orchestrator): Runs on sandbox nodes. It manages Firecracker microVMs, networking, and storage. It communicates with the API via gRPC. - Envd (
packages/envd): An in-VM agent running inside the Firecracker microVM to manage user processes. - Template Manager (
packages/template-manager): A specialized service (using the orchestrator binary) that handles template creation and interacts with object storage.
Data Stores
- PostgreSQL: Stores teams, templates, builds, and snapshots.
- Redis: Tracks running sandboxes, the routing catalog, and caches.
- ClickHouse: Stores metrics, events, and optional logs.
- Object Storage (GCS/S3): Stores template and snapshot artifacts.
- API (
Understand the E2B Infrastructure service layout
mainThe E2B infrastructure is composed of several specialized packages that manage the lifecycle of sandboxes, traffic routing, and data storage:
- api: The control-plane REST API.
- orchestrator: The sandbox runtime and template builder. It runs as a single binary per node.
- client-proxy: An edge router used for sandbox traffic.
- envd: An agent that runs inside the VM.
- dashboard-api: The backend for the web dashboard.
- docker-reverse-proxy: A registry authentication gateway for template images.
- auth: An authentication library (supporting API keys, JWT/OIDC) used by the
apianddashboard-api. - db: Contains Postgres migrations (using
goose) and queries (usingsqlc). - clickhouse: Manages ClickHouse schemas, batching writers, and query clients.
- shared: Contains common protos, telemetry, storage clients, the proxy engine, and feature flags.
- nomad-nodepool-apm: Provides Nomad autoscaler metric and deployment-aware target plugins.
- local-dev: Provides a
docker-composelocal stack and DB seeding for development.
What is envd
mainenvd is a daemon designed to run inside a sandbox. It provides an interface that allows interaction with the sandbox via calls from an SDK.Overview of E2B Data Stores
mainE2B uses several specialized data stores to manage different aspects of the infrastructure:
- PostgreSQL (
packages/db): Stores durable control-plane state includingteams,users,tiers,project_limits,envs(templates),env_builds,env_aliases,snapshots(paused sandboxes),team_api_keys,access_tokens,volumes, andclusters. - Redis: Manages ephemeral runtime state, acting as the source of truth for running sandboxes, the sandbox→node routing catalog, caches (team/template/snapshot), rate limiting, and the P2P chunk peer registry.
- ClickHouse (
packages/clickhouse): Handles time-series and analytics data such asmetrics_gauge/metrics_sum(via OTel),sandbox_events,sandbox_host_stats, and team metrics. - Object Storage (GCS/S3/local,
packages/shared/pkg/storage): Stores template and snapshot artifacts. Artifacts are keyed bybuildIDand include{buildID}/memfile,{buildID}/rootfs.ext4,{buildID}/snapfile, and{buildID}/metadata.json+.headerindex files. - Consul KV: Used by the orchestrator for network slot allocation across restarts.
- PostgreSQL (
How nomad-deployment-aware-target works
mainThe
nomad-deployment-aware-targetmanages scaling to prevent conflicts with active Nomad deployments:- It serializes scaling per namespaced job and acts as a no-op if the current count already matches the desired count.
- If the count must change, it intentionally fails any conflicting active deployment (Nomad will record the deployment as
failedrather thancancelled). - It rereads the job and scales using the current job modify index.
- It verifies the final count; the new rollout proceeds normally.
- Concurrent changes are retried with a bounded attempt count.
Note: Dry-run actions do not fail deployments or write task-group counts.
How the Client Proxy handles sandbox traffic
mainThe Client Proxy (
packages/client-proxy) is a stateless edge router (port 3002) that terminates requests forhttps://<port>-<sandboxID>.<domain>.Traffic Flow:
- The proxy parses the host to identify the
sandboxID. - It looks up the sandbox in the Redis routing catalog to find the owning node.
- It reverse-proxies the request to that node's orchestrator proxy on port 5007.
- Transparent Wake: If the sandbox is not in the catalog (meaning it is paused), the proxy calls the API's
ResumeSandboxgRPC method and retries the request, allowing paused sandboxes to wake up transparently upon incoming traffic.
- The proxy parses the host to identify the
AWS Architecture for E2B deployment
mainThe AWS deployment uses EC2 Auto Scaling Groups for various node pools:
- Control Server: Nomad/Consul servers (default: 3x
t3.medium). - API: API server, ingress, client proxy, otel, loki, logs collector (default:
t3.xlarge). - Client: Firecracker orchestrator nodes with nested virtualization (default:
m8i.4xlarge). - Build: Template manager for building sandbox templates (default:
m8i.2xlarge). - ClickHouse: Analytics database (default:
t3.xlarge).
Managed Services:
- ElastiCache Redis: Can be enabled by setting
REDIS_MANAGED=true.
- Control Server: Nomad/Consul servers (default: 3x
Understand the Redis Reservation Storage flow
mainThe
Redis Reservation Storagepackage manages sandbox creation reservations across multiple API instances to prevent over-provisioning and ensure atomicity.The Reservation Lifecycle
Reserve: Executes a Lua script that performs several atomic operations:
- Removes stale pending entries.
- Checks if the sandbox already exists or has a pending start.
- Enforces team limits by calculating
SCARD(storage index) + ZCARD(pending zset). - Deletes stale result keys.
- Adds the
sandboxIDto the pending zset.
Completion: Once creation is finished, the system:
- Removes the sandbox from the pending zset.
- Writes a result key with a TTL containing either the sandbox object or a creation error.
- Publishes a message to the PubSub routing key.
Waiting: A waiter process subscribes to the PubSub routing key, probes the result key immediately, and then waits for either a PubSub notification or a 1-second fallback ticker. Note: PubSub is best-effort; the 1-second fallback ticker is required to ensure correctness.
Release: Triggered when a sandbox is removed from storage (
Store.Remove). It removes the sandbox from the pending zset, deletes the result key, and publishes to the routing key.
How nomad-nodepool-apm works
mainThe
nomad-nodepool-apmplugin follows these steps to provide metrics to the Nomad Autoscaler:- Queries the Nomad API to list nodes filtered by the node pool name provided in the
queryparameter. - Counts only nodes with a status of
ready. - Returns this count as a metric.
- When used with a
pass-throughstrategy, this count is treated as the desired number of allocations.
- Queries the Nomad API to list nodes filtered by the node pool name provided in the
Configure architecture and cross-architecture deployment
mainThe orchestrator supports
amd64andarm64. While architecture is detected automatically at compile time, you can override runtime behavior using environment variables.Cross-Architecture Deployment
Use the
TARGET_ARCHenvironment variable to override the architecture used for path resolution (kernels/Firecracker) and OCI image pulls. This is a runtime setting.# Run orchestrator targeting amd64 paths from an arm64 host TARGET_ARCH=amd64 ./bin/orchestratorBuilding for ARM64
To build the binaries themselves for ARM64, use the
BUILD_ARCHenvironment variable during the build process.# Build ARM64 binaries BUILD_ARCH=arm64 make build-localArchitecture Naming Convention
The project uses Go/Docker/Debian naming (
amd64/arm64) for directory paths and GCS buckets, rather than Linux/GNU naming (x86_64/aarch64).TARGET_ARCH=amd64 ./bin/orchestratorKernel and Module Limitations in Sandboxes
mainSandboxes always boot using the kernel supplied by E2B, rather than the kernel from the base image. This leads to the following constraints:
/lib/modulesis always empty.- No kernel modules can be loaded.
- SELinux is disabled.
- Installing
kernel-develfrom a distro's repositories will resolve against a kernel that is not actually running.
Important Compatibility Note: Because of these kernel constraints, specific distributions that rely on specific kABI, signed kernel modules, or UEK are not accepted, even if they use supported package managers (RPM/dnf). These include:
- RHEL (including UBI)
- Oracle Linux (
ol) - Amazon Linux (
amzn)
Community rebuilds of these distributions are supported only if they are chosen for their userland rather than their kernel properties.