- Introduction
- Prerequisites
- Deployment (New VPC)
- Deployment (Existing VPC)
- Using E2B CLI
- E2B SDK Cookbook
- Troubleshooting
- Resource Cleanup
- License
E2B on AWS provides a secure, scalable, and customizable environment for running AI agent sandboxes in your own AWS account. This project addresses the growing need for organizations to maintain control over their AI infrastructure while leveraging the power of E2B's sandbox technology for AI agent development, testing, and deployment.
Built based on version
0c35ed5. If you encounter any issues, please submit a PR directly. Special thanks to all contributors involved in the project transformation.
| Requirement | Description |
|---|---|
| AWS Account | With appropriate permissions |
| Domain Name | A domain you own (Cloudflare recommended) |
| Grafana Account | (Optional) For monitoring and logging |
| Posthog Account | (Optional) For analytics |
🔒 Production Security Checklist
Before deploying to production, verify these critical security and reliability settings are enabled:
DB_INSTANCE_BACKUP_ENABLEDRDS_AUTOMATIC_MINOR_VERSION_UPGRADE_ENABLEDRDS_ENHANCED_MONITORING_ENABLEDRDS_INSTANCE_LOGGING_ENABLEDRDS_MULTI_AZ_SUPPORTS3_BUCKET_LOGGING_ENABLEDIMDSv2 enforced- Instance Metadata Service v2 is required on all EC2 instances (HttpTokens: required)
To deploy into an existing VPC instead, see Deployment (Existing VPC).
- Clone this repository
- Open AWS CloudFormation console and create a new stack
- Upload the
e2b-setup-env.ymlfile - Configure the following parameters:
| Parameter | Description |
|---|---|
| Stack Name | Must be lowercase (e.g., e2b-infra) |
| VPC Configuration | New VPC environment configuration |
| Environment | dev or prod (prod has stricter resource protection) |
| Architecture | x64 or AWS Graviton |
| Domain | A domain you own (e.g., example.com) |
| EC2 Key Pair | Existing key pair for SSH access |
| AllowRemoteSSHIPs | IP range for SSH access (defaults to private networks) |
| Database Settings | RDS password: 8-30 characters with letters and numbers |
- Complete all required fields and launch the stack
Note: See AWS Graviton Technical Guide for Graviton best practices.
- Navigate to Amazon Certificate Manager (ACM)
- Find your domain certificate and note the required CNAME record
- Add the CNAME record to your DNS settings (Cloudflare DNS)
- Wait for domain validation (typically 5 minutes)
# Option A: SSH with your key pair
ssh -i your-key.pem ubuntu@<instance-ip>
# Option B: AWS Session Manager from the EC2 consolesudo su root
tail -f /tmp/e2b.log- Wildcard DNS: Add a
*CNAME record pointing to the Application Load Balancer (ALB) DNS name - Nomad Dashboard: Navigate to
https://nomad.<your-domain> - Retrieve Token: Run
cat /opt/config.propertiesto get the Nomad management token
📊 Configure E2B Monitoring (Optional)
- Login to https://grafana.com/ (register if needed)
- Access your settings page at
https://grafana.com/orgs/<username> - In your Stack, find Manage your stack page
- Find OpenTelemetry and click Configure
- Note the following values:
Endpoint for sending OTLP signals: xxxx Instance ID: xxxxxxx Password / API Token: xxxxx - Export Grafana environment variables:
cat << EOF >> /opt/config.properties # Grafana configuration grafana_otel_collector_token=xxx grafana_otlp_url=xxx grafana_username=xxx EOF
- Deploy OpenTelemetry collector:
bash nomad/deploy.sh otel-collector
- Open Grafana Cloud Dashboard to view metrics, traces, and logs
Create a template:
# Create from e2bdev/code-interpreter (default)
bash packages/create_template.sh
# Create from a Dockerfile
bash packages/create_template.sh --docker-file <Docker_File_Path>
# Example: Desktop
bash packages/create_template.sh --docker-file test_use_case/Dockerfile/e2b.Dockerfile.Desktop
# Example: BrowserUse
bash packages/create_template.sh --docker-file test_use_case/Dockerfile/e2b.Dockerfile.BrowserUse
# Example: S3FS
bash packages/create_template.sh --docker-file test_use_case/Dockerfile/e2b.Dockerfile.s3fs
# Example: Code Interpreter (customized)
bash packages/create_template.sh --docker-file test_use_case/Dockerfile/e2b.Dockerfile.code_interpreter
# Create from an ECR image in your own account
bash packages/create_template.sh --ecr-image <ECR_IMAGE_URI>Create a sandbox:
# Get e2b_API value from: cat ../infra-iac/db/config.json
curl -X POST \
https://api.<e2bdomain>/sandboxes \
-H "X-API-Key: <e2b_API>" \
-H 'Content-Type: application/json' \
-d '{
"templateID": "<template_ID>",
"timeout": 3600,
"autoPause": true,
"metadata": { "purpose": "test" }
}'If you already have a VPC with subnets configured, use the e2b-setup-env-existing-vpc.yml template instead.
- Open AWS CloudFormation console and create a new stack
- Upload the
e2b-setup-env-existing-vpc.ymlfile - Configure the following parameters:
| Parameter | Description |
|---|---|
| Stack Name | Must be lowercase (e.g., e2b-infra) |
ExistingVpcId |
Your existing VPC ID |
ExistingPrivateSubnet1Id / 2Id |
Private subnet IDs (two AZs) |
ExistingPublicSubnet1Id / 2Id |
Public subnet IDs (two AZs) |
PublicAccess |
public or private access mode |
| Architecture, Domain, Key Pair, DB | Same as standard deployment |
- The template automatically discovers your VPC CIDR block via a Lambda function
Domain validation, bastion access, DNS setup, monitoring, and testing follow the same process as the standard deployment starting from Step 2.
Note: The existing VPC template uses Aurora Serverless PostgreSQL and Redis Serverless.
# Installation Guide: https://e2b.dev/docs/cli
# macOS
brew install e2b
# Export environment variables
# (query accessToken and teamApiKey from /opt/config.properties)
export E2B_API_KEY=xxx
export E2B_ACCESS_TOKEN=xxx
export E2B_DOMAIN="<e2bdomain>"
# Common commands
e2b sandbox list # List all sandboxes
e2b sandbox connect <sandbox-id> # Connect to a sandbox
e2b sandbox kill <sandbox-id> # Kill a sandbox
e2b sandbox kill --all # Kill all sandboxesgit clone https://github.com/e2b-dev/e2b-cookbook.git
cd e2b-cookbook/examples/hello-world-python
poetry install
# Edit .env and set E2B_API_KEY
vim .env
poetry run startNo nodes were eligible for evaluation
Check node status and constraints in the Nomad dashboard.
Driver Failure: Failed to pull from ECR
Error: pull access denied ... Your authorization token has expired
Solution: Execute aws ecr get-login-password --region us-east-1 to get a new ECR token and update the HCL file.
For other unresolved issues, contact support.
When you need to delete the E2B environment, follow these steps:
1. Terraform Resource Cleanup
cd ~/infra-iac/terraform/
terraform destroyNote: S3 Buckets must be manually emptied first. ALBs may require manual deletion through the AWS console.
2. CloudFormation Stack Cleanup
- Disable RDS deletion protection through the RDS console first
- Then delete the CloudFormation stack
3. Manual Verification
After automated cleanup, verify in the AWS console that all resources are removed:
| Service | Check |
|---|---|
| EC2 | Instances, Security Groups, Load Balancers |
| S3 | Buckets |
| RDS | Database instances |
| ECR | Container repositories |
See CONTRIBUTING for more information.
This project is licensed under the Apache-2.0 License.