Skip to content

Commit 4cf0835

Browse files
committed
init
1 parent 1a272f1 commit 4cf0835

File tree

612 files changed

+119146
-7
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

612 files changed

+119146
-7
lines changed

Makefile

Lines changed: 335 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 291 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,301 @@
1-
## My Project
1+
# E2B on AWS Deployment Guide
22

3-
TODO: Fill this README out!
3+
## Introduction
44

5-
Be sure to:
5+
### Purpose
6+
7+
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.
8+
9+
This project is built based on version c746fd93d5f1260315c893dbd5d7290c0a41e52a (Mar 2), with newer versions still undergoing modifications. This E2B deployment can be used for testing purposes. If you encounter any issues, please contact the relevant team members or submit a PR directly. We would like to express our special thanks to all contributors involved in the project transformation.
10+
11+
12+
## Table of Contents
13+
- [Prerequisites](#prerequisites)
14+
- [Deployment Steps](#deployment-steps)
15+
- [1. Setup EC2 Deployment Machine](#1-setup-ec2-deployment-machine)
16+
- [2. Setup E2B Infrastructure](#2-setup-e2b-infrastructure)
17+
- [3. Deploy Applications](#3-deploy-applications)
18+
- [4. Setup Database](#4-setup-database)
19+
- [5. Configure Grafana Monitoring](#5-configure-grafana-monitoring)
20+
- [6. Test Sandbox SDK](#6-test-sandbox-sdk)
21+
- [Using E2B CLI](#using-e2b-cli)
22+
- [E2B SDK Cookbook](#e2b-sdk-cookbook)
23+
- [Troubleshooting](#troubleshooting)
24+
- [Appendix](#appendix)
25+
- [Architecture Diagram](#architecture-diagram)
26+
27+
## Prerequisites
28+
- An AWS account with appropriate permissions
29+
- A domain name that you own
30+
31+
Recommended for monitoring and logging
32+
- Grafana Account & Stack (see Step 15 for detailed notes)
33+
- Posthog Account
34+
35+
> **Important Production Note:** When deploying to a production environment, ensure the following settings are enabled for security and reliability:
36+
> - `DB_INSTANCE_BACKUP_ENABLED`
37+
> - `RDS_AUTOMATIC_MINOR_VERSION_UPGRADE_ENABLED`
38+
> - `RDS_ENHANCED_MONITORING_ENABLED`
39+
> - `RDS_INSTANCE_LOGGING_ENABLED`
40+
> - `RDS_MULTI_AZ_SUPPORT`
41+
> - `S3_BUCKET_LOGGING_ENABLED`
42+
> - `EC2 Metadata service configuration`
43+
44+
## Deployment Steps
45+
46+
### 1. Setup EC2 Deployment Machine
47+
48+
1. Download CloudFormation template:
49+
2. In AWS CloudFormation service, use the downloaded YAML file:e2b-setup-env.yml
50+
- In 'Domain Configuration', input a domain you own (e.g., `e2b.example.com`)
51+
- Choose an existing EC2 key pair for SSH access (Session Manager is also supported)
52+
- Complete all required fields and launch the CloudFormation stack
53+
3. Modify AllowRemoteSSHIPs(Note: For compliance and security reasons, we've restricted SSH access to a private IP range instead of allowing access from any IP address (10.0.0.0/0). This follows the principle of least privilege by limiting SSH access to your corporate network. Please adjust this value based on your specific network configuration.)
54+
4. Fill in the database information, paying attention to the password rules.
55+
5. After submitting the creation, refresh at the resources section.
56+
6. Go to Amazon Certificate Manager (ACM) to validate your domain:
57+
- Click on your domain to find the required CNAME record for validation
58+
7. Add the CNAME record to your domain's DNS settings
59+
8. Wait for ACM domain validation (typically 5-10 minutes) until CloudFormation stack completes
60+
61+
### 2. Setup E2B Infrastructure
62+
63+
1. SSH into your deployment machine using your preferred SSH client or Session Manager
64+
2. Execute the following commands:
65+
66+
```bashPackage all code, upload to S3, copy the code to the deployment machine created via CloudFormation, and switch to root
67+
sudo su root
68+
cd infra-iac/
69+
bash init.sh
70+
more /opt/config.properties # Confirm the environment exists
71+
72+
cd packer
73+
bash packer.sh
74+
# If there's an error, try executing it one more time
75+
76+
cd ../terraform
77+
bash start.sh
78+
# Wait until the terraform deployment completes
79+
```
80+
81+
82+
4. Configure DNS and scaling:
83+
- Add a CNAME record for `*` with the value set to the DNS name of the automatically created ALB
84+
- Set Auto Scaling groups for API instances to 1 or 2 (default is 0)
85+
- Run `more /opt/config.properties | grep SECRET_NOMAD_ACL_TOKEN` to get the NOMAD token
86+
- Access `nomad.<dns-yourself>` with the token to view the NOMAD dashboard
87+
88+
### 3. Deploy Applications
89+
90+
#### Configuration
91+
92+
Several images are stored in the public registry. For production, it's recommended to build your own images and upload them to your ECR:
93+
- Navigate to `~/infra/package` directory
94+
- Run `bash build.sh`
95+
96+
97+
#### Deploy Nomad Applications
98+
99+
```bash
100+
cd ../nomad
101+
source nomad.sh
102+
bash ./prepare.sh
103+
104+
# Deploy all applications at once
105+
bash ./deploy.sh
106+
107+
108+
# There are 10 applications in total
109+
```
110+
111+
### 4. Setup Database
112+
113+
```bash
114+
cd /opt/infra/e2b-infra-aws/infra-iac/db
115+
bash init-db.sh
116+
117+
# Save the following token information for later use:
118+
# User: xxx
119+
# Team ID: <ID>
120+
# Access Token: <e2b_token>
121+
# Team API Key: <e2b_API>
122+
```
123+
124+
### 5. Configure Grafana Monitoring
125+
126+
1. Login to https://grafana.com/ (register if needed)
127+
2. Access your settings page at https://grafana.com/orgs/<username>
128+
3. In your Stack, find 'Manage your stack' page
129+
4. Find 'OpenTelemetry' and click 'Configure'
130+
5. Note the following values from the dashboard:
131+
```
132+
Endpoint for sending OTLP signals: xxxx
133+
Instance ID: xxxxxxx
134+
Password / API Token: xxxxx
135+
```
136+
137+
6. Export NOMAD environment variables:
138+
```bash
139+
cat << EOF >> /opt/config.properties
140+
141+
# Grafana configuration
142+
grafana_otel_collector_token=xxx
143+
grafana_otlp_url=xxx
144+
grafana_username=xxx
145+
EOF
146+
147+
echo "Appended Grafana configuration to /opt/config.properties"
148+
```
149+
150+
7. Deploy OpenTelemetry collector:
151+
```bash
152+
cd ~/e2b-on-aws/infra-iac/nomad
153+
bash ./deploy.sh otel-collector
154+
```
155+
156+
8. Open Grafana Cloud Dashboard to view metrics, traces, and logs
157+
158+
### 6. Test Sandbox SDK
159+
160+
Test creation template(The script includes the following steps 1-6)
161+
```bash
162+
cd ~/e2b-on-aws/infra/infra-iac/nomad
163+
bash ./create_template.sh
164+
```
165+
166+
1. In EC2 Auto Scaling Group, set the desired capacity of **e2b-0516-client** server to 1
167+
2. Create a sandbox template:
168+
169+
```bash
170+
curl -X POST \
171+
https://api.e2b.example.com/templates \
172+
-H 'Authorization: <e2b_token>' \
173+
-H 'Content-Type: application/json' \
174+
-d '{
175+
"dockerfile": "FROM ubuntu:22.04\nRUN apt-get update && apt-get install -y python3\nCMD [\"python3\", \"-m\", \"http.server\", \"8080\"]",
176+
"memoryMB": 4096,
177+
"cpuCount": 4,
178+
"startCommand": "echo $HOME"
179+
}'
180+
```
181+
182+
3. Save the response (note the buildID and templateID):
183+
```json
184+
{
185+
"aliases": null,
186+
"buildCount": 0,
187+
"buildID": "<buildID>",
188+
"cpuCount": 0,
189+
"createdAt": "0001-01-01T00:00:00Z",
190+
"createdBy": null,
191+
"lastSpawnedAt": "0001-01-01T00:00:00Z",
192+
"memoryMB": 0,
193+
"public": false,
194+
"spawnCount": 0,
195+
"templateID": "<templateID>",
196+
"updatedAt": "0001-01-01T00:00:00Z"
197+
}
198+
```
199+
200+
4. Create ECR registry:
201+
```bash
202+
aws ecr get-login-password --region <AWS_REGION> | docker login --username AWS --password-stdin <AWS_acccount_ID>.dkr.ecr.<AWS_REGION>.amazonaws.com
203+
aws ecr create-repository --repository-name e2bdev/base/<templateID> --region <AWS_REGION> || true
204+
```
205+
206+
5. Pull and push the image:
207+
```bash
208+
docker pull e2bdev/base
209+
210+
aws ecr get-login-password --region <AWS_REGION> | docker login --username AWS --password-stdin <AWS_acccount_ID>.dkr.ecr.<AWS_REGION>.amazonaws.com
211+
docker tag e2bdev/base:latest <AWS_acccount_ID>.dkr.ecr.<AWS_REGION>.amazonaws.com/e2bdev/base/<templateID>:<buildID>
212+
docker push <AWS_acccount_ID>.dkr.ecr.<AWS_REGION>.amazonaws.com/e2bdev/base/<templateID>:<buildID>
213+
```
214+
215+
6. Build RootFS:
216+
```bash
217+
curl -X POST \
218+
https://api.e2b.example.com/templates/<templateID>/builds/<buildID> \
219+
-H 'Authorization: <e2b_token>' \
220+
-H 'Content-Type: application/json'
221+
```
222+
223+
7. Check API and Template Manager logs in Nomad Console for any issues
224+
8. Create a sandbox(Get the value of e2b_API to execute commands--- more ../infra-iac/db/config.json):
225+
```bash
226+
curl -X POST \
227+
https://api.e2b.example.com/sandboxes \
228+
-H "X-API-Key: <e2b_API>" \
229+
-H 'Content-Type: application/json' \
230+
-d '{
231+
"templateID": "<template_ID>",
232+
"timeout": 3600,
233+
"autoPause": true,
234+
"envVars": {
235+
"EXAMPLE_VAR": "example_value"
236+
},
237+
"metadata": {
238+
"purpose": "test"
239+
}
240+
}'
241+
```
242+
243+
## Using E2B CLI
244+
245+
```bash
246+
# Installation Guide: https://e2b.dev/docs/cli
247+
# For macOS
248+
brew install e2b
249+
250+
# Export environment variables
251+
export E2B_API_KEY=xxx
252+
export E2B_ACCESS_TOKEN=xxx
253+
export E2B_DOMAIN="e2b.example.com"
254+
255+
# Common E2B CLI commands
256+
# List all sandboxes
257+
e2b sandbox list
258+
259+
# Connect to a sandbox
260+
e2b sandbox connect <sandbox-id>
261+
262+
# Kill a sandbox
263+
e2b sandbox kill <sandbox-id>
264+
e2b sandbox kill --all
265+
```
266+
267+
## E2B SDK Cookbook
268+
269+
```bash
270+
git clone https://github.com/e2b-dev/e2b-cookbook.git
271+
cd e2b-cookbook/examples/hello-world-python
272+
poetry install
273+
274+
# Edit .env file
275+
vim .env
276+
# Change E2B_API_KEY value
277+
278+
poetry run start
279+
```
280+
281+
## Troubleshooting
282+
283+
1. **No nodes were eligible for evaluation error when deploying applications**
284+
- Check node status and constraints
285+
286+
2. **Driver Failure: Failed to pull from ECR**
287+
- Error: `Failed to pull xxx.dkr.ecr.us-west-2.amazonaws.com/e2b-orchestration/api:latest: API error (404): pull access denied for xxx.dkr.ecr.us-west-2.amazonaws.com/e2b-orchestration/api, repository does not exist or may require 'docker login': denied: Your authorization token has expired. Reauthenticate and try again.`
288+
- Solution: Execute `aws ecr get-login-password --region us-east-1` to get a new ECR token and update the HCL file
289+
290+
3. For other unresolved issues, contact support
291+
292+
## Appendix
6293

7-
* Change the title in this README
8-
* Edit your repository description on GitHub
9294

10295
## Security
11296

12297
See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information.
13298

14299
## License
15300

16-
This project is licensed under the Apache-2.0 License.
17-
301+
This project is licensed under the Apache-2.0 License.

0 commit comments

Comments
 (0)