Base image
How to define a base image for your template
Creating template
When creating a template, you can specify options:
const template = Template({
fileContextPath: ".", // Custom file context path
fileIgnorePatterns: [".git", "node_modules"], // File patterns to ignore
});File ignoring: The SDK automatically reads .dockerignore files and combines them with your fileIgnorePatterns (TypeScript) or file_ignore_patterns (Python). Files matching these patterns are excluded from uploads and hash calculations.
Defining base image
Every template starts with a base image that provides the foundation for your sandbox environment.
E2B currently supports only Debian-based images. Your base image must be Debian or a Debian derivative (e.g., debian, ubuntu, python, node). Alpine, RedHat-based, and other non-Debian distributions are not supported.
Predefined base images
Use convenience methods for common base images with Ubuntu, Debian, Python, Node.js, or Bun:
template.fromUbuntuImage("22.04"); // ubuntu:22.04
template.fromDebianImage("stable-slim"); // debian:stable-slim
template.fromPythonImage("3.13"); // python:3.13
template.fromNodeImage("lts"); // node:lts
template.fromBunImage("1.3"); // oven/bun:1.3Custom base image
Use any Docker image from Docker Hub or other registries:
template.fromImage("custom-image:latest");Default E2B base image
Use the default E2B base image, which comes pre-configured for sandbox environments:
template.fromBaseImage(); // e2bdev/basebase is also the template used when you call Sandbox.create() without specifying one. It is Debian-based and comes with common tooling pre-installed: Python 3, Node.js, Yarn, git, curl, build-essential, and the GitHub CLI (gh). For the exact contents, see the public Dockerfile: templates/base/e2b.Dockerfile.
Default resources
A sandbox gets its CPU and memory from the template it’s built on. A sandbox built from base starts with 2 vCPU and 512 MiB of RAM.
You can override CPU and memory when you build a template (cpuCount/cpu_count, memoryMB/memory_mb). Disk size is not a default you set per sandbox; it’s determined by your project’s tier limit and applied at build time (see Build limits).
Build from existing template
Extend an existing template from your project or organization:
template.fromTemplate("my-template"); // Your project's template
template.fromTemplate("acme/other-template"); // Full namespaced referenceYou can only call base image methods once per template. Subsequent calls will throw an error.
Parsing existing Dockerfiles
Convert existing Dockerfiles to template format using fromDockerfile():
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));Dockerfile instructions support
| Instruction | Supported | Behavior |
|---|---|---|
FROM | Sets base image | |
RUN | Converts to runCmd() / run_cmd() | |
COPY / ADD | Converts to copy() | |
WORKDIR | Converts to setWorkdir() / set_workdir() | |
USER | Converts to setUser() / set_user() | |
ENV | Converts to setEnvs() / set_envs(); supports both ENV key=value and ENV key value formats | |
CMD / ENTRYPOINT | Converts to setStartCmd() / set_start_cmd() with 20 seconds timeout as ready command | |
EXPOSE | Skipped (not supported) | |
VOLUME | Skipped (not supported) |
Multi-stage Dockerfiles are not supported.