Skip to content

Commit b0bd68f

Browse files
authored
Merge pull request #3 from e2b-dev/template-sdk-docs
2 parents f5da086 + 49bd21f commit b0bd68f

17 files changed

+1579
-92
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea

docs.json

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,50 +3,40 @@
33
"theme": "mint",
44
"name": "E2B Documentation",
55
"colors": {
6-
"primary": "#16A34A",
7-
"light": "#07C983",
8-
"dark": "#15803D"
6+
"primary": "#FF8800",
7+
"light": "#FF8800",
8+
"dark": "#E57B00"
99
},
10-
"favicon": "/favicon.svg",
10+
"favicon": "/favicon.png",
1111
"navigation": {
1212
"anchors": [
1313
{
1414
"anchor": "Documentation",
1515
"icon": "book-open",
1616
"groups": [
1717
{
18-
"group": "Getting Started",
19-
"pages": ["What's E2B?", "Quickstart", "Getting API Key"]
20-
},
21-
{
22-
"group": "Sandbox",
18+
"group": "Custom sandbox",
2319
"pages": [
24-
"Sandbox lifecycle",
25-
"Environment variables",
26-
"Filesystem",
27-
"Commands",
28-
"Reconnect",
29-
"Internet access"
20+
"template/quickstart",
21+
"template/how-it-works",
22+
{
23+
"group": "Customization",
24+
"icon": "wand-magic-sparkles",
25+
"pages": [
26+
"template/customization/authentication",
27+
"template/customization/base-image",
28+
"template/customization/defining-template",
29+
"template/customization/start-ready-command",
30+
"template/customization/build",
31+
"template/customization/logging",
32+
"template/customization/error-handling"
33+
]
34+
},
35+
"template/examples",
36+
"template/migration"
3037
]
31-
},
32-
{
33-
"group": "Custom sandbox",
34-
"pages": ["Quickstart", "Overview"]
35-
},
36-
{
37-
"group": "Premade sandboxes",
38-
"pages": ["Base", "Code interpreter", "Desktop"]
39-
},
40-
{
41-
"group": "Deploy E2B",
42-
"pages": ["deployment/byoc", "deployment/self-hosting"]
4338
}
4439
]
45-
},
46-
{
47-
"anchor": "SDK Reference",
48-
"icon": "square-terminal",
49-
"href": "https://external-link.com/blog"
5040
}
5141
]
5242
},
@@ -58,7 +48,7 @@
5848
"primary": {
5949
"type": "button",
6050
"label": "Dashboard",
61-
"href": "https://dashboard.mintlify.com"
51+
"href": "https://e2b.dev/dashboard"
6252
}
6353
},
6454
"contextual": {

favicon.png

88.4 KB
Loading

favicon.svg

Lines changed: 0 additions & 19 deletions
This file was deleted.

logo/dark.svg

Lines changed: 5 additions & 20 deletions
Loading

logo/light.svg

Lines changed: 5 additions & 20 deletions
Loading
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
title: "Authentication"
3+
description: "How to login to the E2B Cloud"
4+
icon: "key"
5+
---
6+
7+
The SDK uses environment variables for authentication:
8+
9+
- `E2B_API_KEY`: Your E2B API key
10+
- `E2B_DOMAIN`: (Optional) E2B domain, defaults to 'e2b.dev'
Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
---
2+
title: "Base Image"
3+
description: "How to define a base image for your template"
4+
icon: "1"
5+
---
6+
7+
## Creating template
8+
9+
When creating a template, you can specify options:
10+
11+
<CodeGroup dropdown>
12+
13+
```typescript
14+
const template = Template({
15+
fileContextPath: ".", // Custom file context path
16+
ignoreFilePaths: [".git", "node_modules"], // File patterns to ignore
17+
});
18+
```
19+
20+
```python
21+
template = Template(
22+
file_context_path=".", # Custom file context path
23+
ignore_file_paths=[".git", "node_modules"], # File patterns to ignore
24+
)
25+
```
26+
27+
</CodeGroup>
28+
29+
**File ignoring**: The SDK automatically reads `.dockerignore` files and combines them with your `ignoreFilePaths`. Files matching these patterns are excluded from uploads and hash calculations.
30+
31+
## Defining base image
32+
Choose from predefined base images or use custom ones:
33+
34+
<CodeGroup dropdown>
35+
36+
```typescript
37+
// Predefined base images
38+
template.fromUbuntuImage("lts"); // ubuntu:lts
39+
template.fromUbuntuImage("22.04"); // ubuntu:22.04
40+
template.fromDebianImage("slim"); // debian:slim
41+
template.fromDebianImage("bullseye"); // debian:bullseye
42+
template.fromPythonImage("3.13"); // python:3.13
43+
template.fromPythonImage("3.11"); // python:3.11
44+
template.fromNodeImage("lts"); // node:lts
45+
template.fromNodeImage("20"); // node:20
46+
47+
// Custom base image
48+
template.fromImage("custom-image:latest");
49+
50+
// Use default E2B base image
51+
template.fromBaseImage(); // e2bdev/base
52+
53+
// Parse existing Dockerfile
54+
const dockerfileContent = `
55+
FROM node:18-alpine
56+
WORKDIR /app
57+
COPY package*.json ./
58+
RUN npm ci --only=production
59+
COPY . .
60+
ENV NODE_ENV=production`;
61+
62+
template.fromDockerfile(dockerfileContent);
63+
```
64+
65+
```python
66+
# Predefined base images
67+
template.from_ubuntu_image("lts") # ubuntu:lts
68+
template.from_ubuntu_image("22.04") # ubuntu:22.04
69+
template.from_debian_image("slim") # debian:slim
70+
template.from_debian_image("bullseye") # debian:bullseye
71+
template.from_python_image("3.13") # python:3.13
72+
template.from_python_image("3.11") # python:3.11
73+
template.from_node_image("lts") # node:lts
74+
template.from_node_image("20") # node:20
75+
76+
# Custom base image
77+
template.from_image("custom-image:latest")
78+
79+
# Use default E2B base image
80+
template.from_base_image() # e2bdev/base
81+
82+
# Build from existing template
83+
template.from_template("existing-template-alias")
84+
85+
# Parse and build from Dockerfile
86+
template.from_dockerfile("Dockerfile")
87+
template.from_dockerfile("FROM ubuntu:22.04\nRUN apt-get update")
88+
```
89+
90+
</CodeGroup>
91+
92+
<Note>
93+
You can only call base image methods once per template. Subsequent calls will throw an error.
94+
</Note>
95+
96+
## Parsing existing Dockerfiles
97+
98+
Convert existing Dockerfiles to template format using `fromDockerfile()`:
99+
100+
<CodeGroup dropdown>
101+
102+
```typescript
103+
const dockerfileContent = `
104+
FROM ubuntu:22.04
105+
RUN apt-get update && apt-get install -y curl
106+
WORKDIR /app
107+
COPY . .
108+
ENV NODE_ENV=production
109+
ENV PORT=3000
110+
USER appuser`;
111+
112+
const template = Template()
113+
.fromDockerfile(dockerfileContent)
114+
.setStartCmd("npm start", waitForTimeout(5_000));
115+
```
116+
117+
```python
118+
dockerfile_content = """
119+
FROM ubuntu:22.04
120+
RUN apt-get update && apt-get install -y curl
121+
WORKDIR /app
122+
COPY . .
123+
ENV NODE_ENV=production
124+
ENV PORT=3000
125+
USER appuser
126+
"""
127+
128+
template = (
129+
Template()
130+
.from_dockerfile(dockerfile_content)
131+
.set_start_cmd("npm start", wait_for_timeout(5_000))
132+
)
133+
```
134+
135+
</CodeGroup>
136+
137+
### Dockerfile instructions support
138+
139+
| Instruction | Supported | Behavior |
140+
| :--- | :----: | :--- |
141+
| `FROM` | <Icon icon="square-check" iconType="solid" /> | Sets base image |
142+
| `RUN` | <Icon icon="square-check" iconType="solid" /> | Converts to `runCmd()` / `run_cmd()` |
143+
| `COPY` / `ADD` | <Icon icon="square-check" iconType="solid" /> | Converts to `copy()` |
144+
| `WORKDIR` | <Icon icon="square-check" iconType="solid" /> | Converts to `setWorkdir()` / `set_workdir()` |
145+
| `USER` | <Icon icon="square-check" iconType="solid" /> | Converts to `setUser()` / `set_user()` |
146+
| `ENV` | <Icon icon="square-check" iconType="solid" /> | Converts to `setEnvs()` / `set_envs()`; supports both `ENV key=value` and `ENV key value` formats |
147+
| `CMD` / `ENTRYPOINT` | <Icon icon="square-check" iconType="solid" /> | Converts to `setStartCmd()` / `set_start_cmd()` with 20 seconds timeout as ready command |
148+
| `EXPOSE` | <Icon icon="xmark" iconType="solid" /> | Skipped (not supported) |
149+
| `VOLUME` | <Icon icon="xmark" iconType="solid" /> | Skipped (not supported) |
150+
151+
<Warning>
152+
Multi-stage Dockerfiles are not supported.
153+
</Warning>
154+
155+
## Login to private registries
156+
If your base image is hosted in a private registry, you can provide credentials using the following helpers:
157+
- General registry
158+
- GCP Artifact Registry
159+
- AWS ECR
160+
161+
### General Registry
162+
163+
<CodeGroup dropdown>
164+
165+
```typescript
166+
Template().fromRegistry('ubuntu:22.04', {
167+
username: 'user',
168+
password: 'pass',
169+
})
170+
```
171+
172+
```python
173+
Template().from_registry(
174+
image="ubuntu:22.04",
175+
username="user",
176+
password="pass",
177+
)
178+
```
179+
180+
</CodeGroup>
181+
182+
183+
### GCP Artifact Registry
184+
185+
<CodeGroup dropdown>
186+
187+
```typescript
188+
// From file path
189+
Template().fromGCPRegistry('ubuntu:22.04', {
190+
serviceAccountJSON: './service_account.json',
191+
})
192+
193+
// From object
194+
Template().fromGCPRegistry('ubuntu:22.04', {
195+
serviceAccountJSON: { project_id: '123', private_key_id: '456' },
196+
})
197+
```
198+
199+
```python
200+
# From file path
201+
Template().from_gcp_registry(
202+
image="ubuntu:22.04",
203+
service_account_json="./service_account.json",
204+
)
205+
206+
# From object
207+
Template().from_gcp_registry(
208+
image="ubuntu:22.04",
209+
service_account_json={"project_id": "123", "private_key_id": "456"},
210+
)
211+
```
212+
213+
</CodeGroup>
214+
215+
216+
### AWS ECR
217+
218+
<CodeGroup dropdown>
219+
220+
```typescript
221+
Template().fromAWSRegistry('ubuntu:22.04', {
222+
accessKeyId: '123',
223+
secretAccessKey: '456',
224+
region: 'us-west-1',
225+
})
226+
```
227+
228+
```python
229+
Template().from_aws_registry(
230+
image="ubuntu:22.04",
231+
access_key_id="123",
232+
secret_access_key="456",
233+
region="us-west-1",
234+
)
235+
```
236+
237+
</CodeGroup>

template/customization/build.mdx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
title: "Build"
3+
description: "How to build the template"
4+
icon: "hammer"
5+
---
6+
7+
Configure the build process:
8+
9+
<CodeGroup dropdown>
10+
11+
```typescript wrap
12+
Template.build(template, {
13+
alias: 'my-template', // Template alias (required)
14+
cpuCount: 2, // CPU cores
15+
memoryMB: 2048, // Memory in MB
16+
skipCache: false, // Configure cache skip (except for files)
17+
onBuildLogs: (logEntry) => console.log(logEntry.toString()), // Log callback receives LogEntry objects
18+
apiKey: 'your-api-key', // Override API key
19+
domain: 'your-domain', // Override domain
20+
})
21+
```
22+
23+
```python wrap
24+
Template.build(
25+
template,
26+
alias="my-template", # Template alias (required)
27+
cpu_count=2, # CPU cores
28+
memory_mb=2048, # Memory in MB
29+
skip_cache=False, # Configure cache skip (except for files)
30+
on_build_logs=lambda log_entry: print(log_entry), # Log callback receives LogEntry objects
31+
api_key="your-api-key", # Override API key
32+
domain="your-domain", # Override domain
33+
)
34+
```
35+
36+
</CodeGroup>

0 commit comments

Comments
 (0)