Skip to main content

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.

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

Custom 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/base

Build from existing template

Extend an existing template from your team or organization:
template.fromTemplate("my-template"); // Your team's template
template.fromTemplate("acme/other-template"); // Full namespaced reference
You 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

InstructionSupportedBehavior
FROMSets base image
RUNConverts to runCmd() / run_cmd()
COPY / ADDConverts to copy()
WORKDIRConverts to setWorkdir() / set_workdir()
USERConverts to setUser() / set_user()
ENVConverts to setEnvs() / set_envs(); supports both ENV key=value and ENV key value formats
CMD / ENTRYPOINTConverts to setStartCmd() / set_start_cmd() with 20 seconds timeout as ready command
EXPOSESkipped (not supported)
VOLUMESkipped (not supported)
Multi-stage Dockerfiles are not supported.