Appearance
Template Base Images
The base image is the foundation of a sandbox template, determining the operating system and pre-installed software.
Creating a Template
When creating a template with Template(), you can configure file context options:
javascript
import { Template } from '@e2b/code-interpreter'
const template = Template({
fileContextPath: './my-context', // Custom file context path (default: ".")
fileIgnorePatterns: ['*.log', 'node_modules/**'] // File patterns to exclude
})Rules from a .dockerignore file are automatically integrated; matching files are not uploaded or included in hash calculations.
Defining a Base Image
Predefined Images
Use predefined image methods to quickly specify common environments:
javascript
import { Template } from '@e2b/code-interpreter'
// Ubuntu
const ubuntuTemplate = Template().fromUbuntuImage('jammy') // or '22.04'
// Debian
const debianTemplate = Template().fromDebianImage('stable-slim') // or 'bullseye'
// Python
const pythonTemplate = Template().fromPythonImage('3.13') // or '3.11'
// Node.js
const nodeTemplate = Template().fromNodeImage('lts') // or '20'
// Bun
const bunTemplate = Template().fromBunImage('1.3')These predefined methods pull images from the corresponding official registry. If you are using public registries like Docker Hub in a network environment with restrictions, consider using fromImage() and specifying the full path via a mirror proxy.
Custom Images
Use images from any Docker Registry:
javascript
import { Template } from '@e2b/code-interpreter'
const customTemplate = Template().fromImage(
'crp-internal.sufycs.com/registry-1.docker.io/library/python:3.13'
)Default Base Image
If no image is specified, the E2B default base image is used:
javascript
import { Template } from '@e2b/code-interpreter'
const defaultTemplate = Template() // Uses e2bdev/baseBased on an Existing Template
Create a new template from an existing one:
javascript
import { Template } from '@e2b/code-interpreter'
// Using a template alias
const template = Template().fromTemplate('my-existing-template')
// Using a namespaced template
const nsTemplate = Template().fromTemplate('namespace/template-name')Parsing from a Dockerfile
Convert existing Dockerfile content into a template:
javascript
import { Template } from '@e2b/code-interpreter'
const template = Template().fromDockerfile(`
FROM crp-internal.sufycs.com/registry-1.docker.io/library/python:3.11
RUN pip install numpy pandas
WORKDIR /app
COPY . .
ENV DEBUG=true
CMD ["python", "app.py"]
`)
.pipInstall(['matplotlib']) // Can continue chaining configurationSupported Dockerfile Instructions
| Instruction | Status | Conversion Method |
|---|---|---|
FROM | Supported | Converted to fromImage() |
RUN | Supported | Converted to runCmd() |
COPY/ADD | Supported | Converted to copy() |
WORKDIR | Supported | Converted to setWorkdir() |
USER | Supported | Converted to setUser() |
ENV | Supported | Converted to setEnvs() |
CMD/ENTRYPOINT | Supported | Converted to setStartCmd() |
EXPOSE | Not supported | Skipped |
VOLUME | Not supported | Skipped |
Important Limitations
Base image methods can only be called once: Each template can only set one base image.
javascript
// Error: Cannot set base image multiple times
const template = Template()
.fromImage('crp-internal.sufycs.com/registry-1.docker.io/library/python:3.11')
.fromImage('crp-internal.sufycs.com/registry-1.docker.io/library/node:20') // Error!
// Correct: Set only once
const template = Template().fromImage(
'crp-internal.sufycs.com/registry-1.docker.io/library/python:3.11'
)Multi-stage builds are not supported: Dockerfile parsing does not support multi-stage builds.