How e2b-dev/infra works
Main Components
• API Service – Located under packages/api, this service contains the core logic (handlers, middlewares, authentication, cache, analytics) and is responsible for providing the infrastructure’s API endpoints.
• Client & Reverse Proxy – The packages/client-proxy and packages/docker-reverse-proxy indicate that a client-side proxy layer and a reverse proxy exist. They help route requests and manage inbound traffic.
• Environment & Template Management – With components like packages/envd and packages/template-manager, the system supports managing execution environments and build templates, allowing customization and deployment of “sandboxes.”
• Orchestration – The packages/orchestrator contains logic for sandbox creation, instance lifecycle management, and overall orchestration of compute resources. It interacts with lower-level modules such as nodes, DNS, and caching.
• Database Services – The packages/db area includes migrations, queries, and client code for handling persistent data (e.g., user profiles, team configuration, sandbox metadata).
• Cloud & Cluster Provisioning – The directories under packages/cluster, packages/buckets, and Terraform configurations (e.g., main.tf at the repo’s root; terraform/*) show that Terraform is used to manage and deploy the underlying cloud infrastructure (GCP, AWS, etc.) for clusters, networking, security, and more.
• Firecracker Kernel & Versions – components located in packages/fc-kernels and packages/fc-versions imply that the system uses Firecracker micro-VMs, with dedicated modules for managing kernel versions and VM configuration.
• Shared Libraries – The packages/shared directory provides common utilities, model definitions, logging, telemetry (OpenTelemetry in the middleware), gRPC connections, etc., which support cross-service consistency, especially for communication and monitoring.
Relationships and Data Flows
• Incoming requests typically hit the reverse proxy first. This reverse proxy then directs traffic to the API server and possibly the orchestrator, ensuring security, authentication, and load balancing.
• The API service is the central hub; it processes requests (with middleware layers for tracing and metrics), communicates with the database for persistent data, and coordinates with the orchestrator for resource management.
• The orchestrator and EnvD modules interact to manage the lifecycle of sandboxes and compute instances (which may be implemented via Firecracker). They also interact with client-proxy components to enable low-latency service delivery.
• Template Manager services provide container and environment templates. They coordinate with the API and orchestrator to trigger builds and updates.
• The infrastructure is provisioned and managed through Terraform scripts located in packages/cluster, packages/init, and the terraform/ directories. These scripts establish the network, compute resources, buckets, and security configurations across different cloud providers.
• Shared libraries (for logging, db, grpc, models, telemetry, etc.) support all these components, ensuring that standards are consistently applied across services.
Architectural Patterns
• Microservices: Each major component (API, orchestrator, client proxy, env management, template manager) is grouped into its own package, allowing independent development and deployment.
• Infrastructure-as-Code: The presence of Terraform configurations and various “*.tf” files shows that provisioning and cloud resource management follow declarative patterns.
• Middleware and Observability: OpenTelemetry is integrated across API services and orchestrator modules, indicating a focus on distributed tracing and metrics.
• Modular Design: The partitioning into packages (shared, orchestrator, db, etc.) provides a clear separation of concerns.
Final Assembly
– Start with an external layer: Users or agents send requests to the Reverse Proxy.
– Show the reverse proxy directing traffic to the API service.
• The Database (persistent storage and migrations)
• The Orchestrator (which further manages sandboxes and instances)
• The Template Manager and EnvD (for environment configuration)
– Include connections from the Orchestrator to components like Client Proxy and Firecracker interfaces.
Happy diagramming!