Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
56 changes: 23 additions & 33 deletions docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,50 +3,40 @@
"theme": "mint",
"name": "E2B Documentation",
"colors": {
"primary": "#16A34A",
"light": "#07C983",
"dark": "#15803D"
"primary": "#FF8800",
"light": "#FF8800",
"dark": "#E57B00"
},
"favicon": "/favicon.svg",
"favicon": "/favicon.png",
"navigation": {
"anchors": [
{
"anchor": "Documentation",
"icon": "book-open",
"groups": [
{
"group": "Getting Started",
"pages": ["What's E2B?", "Quickstart", "Getting API Key"]
},
{
"group": "Sandbox",
"group": "Custom sandbox",
"pages": [
"Sandbox lifecycle",
"Environment variables",
"Filesystem",
"Commands",
"Reconnect",
"Internet access"
"template/quickstart",
"template/how-it-works",
{
"group": "Customization",
"icon": "wand-magic-sparkles",
"pages": [
"template/customization/authentication",
"template/customization/base-image",
"template/customization/defining-template",
"template/customization/start-ready-command",
"template/customization/build",
"template/customization/logging",
"template/customization/error-handling"
]
},
"template/examples",
"template/migration"
]
},
{
"group": "Custom sandbox",
"pages": ["Quickstart", "Overview"]
},
{
"group": "Premade sandboxes",
"pages": ["Base", "Code interpreter", "Desktop"]
},
{
"group": "Deploy E2B",
"pages": ["deployment/byoc", "deployment/self-hosting"]
}
]
},
{
"anchor": "SDK Reference",
"icon": "square-terminal",
"href": "https://external-link.com/blog"
}
]
},
Expand All @@ -58,7 +48,7 @@
"primary": {
"type": "button",
"label": "Dashboard",
"href": "https://dashboard.mintlify.com"
"href": "https://e2b.dev/dashboard"
}
},
"contextual": {
Expand Down
Binary file added favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 0 additions & 19 deletions favicon.svg

This file was deleted.

25 changes: 5 additions & 20 deletions logo/dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 5 additions & 20 deletions logo/light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions template/customization/authentication.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
title: "Authentication"
description: "How to login to the E2B Cloud"
icon: "key"
---

The SDK uses environment variables for authentication:

- `E2B_API_KEY`: Your E2B API key
- `E2B_DOMAIN`: (Optional) E2B domain, defaults to 'e2b.dev'
237 changes: 237 additions & 0 deletions template/customization/base-image.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
---
title: "Base Image"
description: "How to define a base image for your template"
icon: "1"
---

## Creating template

When creating a template, you can specify options:

<CodeGroup dropdown>

```typescript
const template = Template({
fileContextPath: ".", // Custom file context path
ignoreFilePaths: [".git", "node_modules"], // File patterns to ignore
});
```

```python
template = Template(
file_context_path=".", # Custom file context path
ignore_file_paths=[".git", "node_modules"], # File patterns to ignore
)
```

</CodeGroup>

**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.

## Defining base image
Choose from predefined base images or use custom ones:

<CodeGroup dropdown>

```typescript
// Predefined base images
template.fromUbuntuImage("lts"); // ubuntu:lts
template.fromUbuntuImage("22.04"); // ubuntu:22.04
template.fromDebianImage("slim"); // debian:slim
template.fromDebianImage("bullseye"); // debian:bullseye
template.fromPythonImage("3.13"); // python:3.13
template.fromPythonImage("3.11"); // python:3.11
template.fromNodeImage("lts"); // node:lts
template.fromNodeImage("20"); // node:20

// Custom base image
template.fromImage("custom-image:latest");

// Use default E2B base image
template.fromBaseImage(); // e2bdev/base

// Parse existing Dockerfile
const dockerfileContent = `
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
ENV NODE_ENV=production`;

template.fromDockerfile(dockerfileContent);
```

```python
# Predefined base images
template.from_ubuntu_image("lts") # ubuntu:lts
template.from_ubuntu_image("22.04") # ubuntu:22.04
template.from_debian_image("slim") # debian:slim
template.from_debian_image("bullseye") # debian:bullseye
template.from_python_image("3.13") # python:3.13
template.from_python_image("3.11") # python:3.11
template.from_node_image("lts") # node:lts
template.from_node_image("20") # node:20

# Custom base image
template.from_image("custom-image:latest")

# Use default E2B base image
template.from_base_image() # e2bdev/base

# Build from existing template
template.from_template("existing-template-alias")

# Parse and build from Dockerfile
template.from_dockerfile("Dockerfile")
template.from_dockerfile("FROM ubuntu:22.04\nRUN apt-get update")
```

</CodeGroup>

<Note>
You can only call base image methods once per template. Subsequent calls will throw an error.
</Note>

## Parsing existing Dockerfiles

Convert existing Dockerfiles to template format using `fromDockerfile()`:

<CodeGroup dropdown>

```typescript
const dockerfileContent = `
FROM ubuntu:22.04
RUN apt-get update && apt-get install -y curl
WORKDIR /app
COPY . .
ENV NODE_ENV=production
ENV PORT=3000
USER appuser`;

const template = Template()
.fromDockerfile(dockerfileContent)
.setStartCmd("npm start", waitForTimeout(5_000));
```

```python
dockerfile_content = """
FROM ubuntu:22.04
RUN apt-get update && apt-get install -y curl
WORKDIR /app
COPY . .
ENV NODE_ENV=production
ENV PORT=3000
USER appuser
"""

template = (
Template()
.from_dockerfile(dockerfile_content)
.set_start_cmd("npm start", wait_for_timeout(5_000))
)
```

</CodeGroup>

### Dockerfile instructions support

| Instruction | Supported | Behavior |
| :--- | :----: | :--- |
| `FROM` | <Icon icon="square-check" iconType="solid" /> | Sets base image |
| `RUN` | <Icon icon="square-check" iconType="solid" /> | Converts to `runCmd()` / `run_cmd()` |
| `COPY` / `ADD` | <Icon icon="square-check" iconType="solid" /> | Converts to `copy()` |
| `WORKDIR` | <Icon icon="square-check" iconType="solid" /> | Converts to `setWorkdir()` / `set_workdir()` |
| `USER` | <Icon icon="square-check" iconType="solid" /> | Converts to `setUser()` / `set_user()` |
| `ENV` | <Icon icon="square-check" iconType="solid" /> | Converts to `setEnvs()` / `set_envs()`; supports both `ENV key=value` and `ENV key value` formats |
| `CMD` / `ENTRYPOINT` | <Icon icon="square-check" iconType="solid" /> | Converts to `setStartCmd()` / `set_start_cmd()` with 20 seconds timeout as ready command |
| `EXPOSE` | <Icon icon="xmark" iconType="solid" /> | Skipped (not supported) |
| `VOLUME` | <Icon icon="xmark" iconType="solid" /> | Skipped (not supported) |

<Warning>
Multi-stage Dockerfiles are not supported.
</Warning>

## Login to private registries
If your base image is hosted in a private registry, you can provide credentials using the following helpers:
- General registry
- GCP Artifact Registry
- AWS ECR

### General Registry

<CodeGroup dropdown>

```typescript
Template().fromRegistry('ubuntu:22.04', {
username: 'user',
password: 'pass',
})
```

```python
Template().from_registry(
image="ubuntu:22.04",
username="user",
password="pass",
)
```

</CodeGroup>


### GCP Artifact Registry

<CodeGroup dropdown>

```typescript
// From file path
Template().fromGCPRegistry('ubuntu:22.04', {
serviceAccountJSON: './service_account.json',
})

// From object
Template().fromGCPRegistry('ubuntu:22.04', {
serviceAccountJSON: { project_id: '123', private_key_id: '456' },
})
```

```python
# From file path
Template().from_gcp_registry(
image="ubuntu:22.04",
service_account_json="./service_account.json",
)

# From object
Template().from_gcp_registry(
image="ubuntu:22.04",
service_account_json={"project_id": "123", "private_key_id": "456"},
)
```

</CodeGroup>


### AWS ECR

<CodeGroup dropdown>

```typescript
Template().fromAWSRegistry('ubuntu:22.04', {
accessKeyId: '123',
secretAccessKey: '456',
region: 'us-west-1',
})
```

```python
Template().from_aws_registry(
image="ubuntu:22.04",
access_key_id="123",
secret_access_key="456",
region="us-west-1",
)
```

</CodeGroup>
36 changes: 36 additions & 0 deletions template/customization/build.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
title: "Build"
description: "How to build the template"
icon: "hammer"
---

Configure the build process:

<CodeGroup dropdown>

```typescript wrap
Template.build(template, {
alias: 'my-template', // Template alias (required)
cpuCount: 2, // CPU cores
memoryMB: 2048, // Memory in MB
skipCache: false, // Configure cache skip (except for files)
onBuildLogs: (logEntry) => console.log(logEntry.toString()), // Log callback receives LogEntry objects
apiKey: 'your-api-key', // Override API key
domain: 'your-domain', // Override domain
})
```

```python wrap
Template.build(
template,
alias="my-template", # Template alias (required)
cpu_count=2, # CPU cores
memory_mb=2048, # Memory in MB
skip_cache=False, # Configure cache skip (except for files)
on_build_logs=lambda log_entry: print(log_entry), # Log callback receives LogEntry objects
api_key="your-api-key", # Override API key
domain="your-domain", # Override domain
)
```

</CodeGroup>
Loading