Skip to main content

TemplateBase

Base class for building E2B sandbox templates.

Implements

  • TemplateFromImage
  • TemplateBuilder
  • TemplateFinal

Constructors

Parameters
ParameterType
options?TemplateOptions
Returns
TemplateBase

Methods

aptInstall()

Install Debian/Ubuntu packages using apt-get.
Parameters
ParameterTypeDescription
packagesstring | string[]Package name(s)
Returns
TemplateBuilder
Example
Implementation of
TemplateBuilder.aptInstall

betaAddMcpServer()

Install MCP servers using mcp-gateway. Note: Requires a base image with mcp-gateway pre-installed (e.g., mcp-gateway).
Parameters
ParameterTypeDescription
serverskeyof McpServer | keyof McpServer[]MCP server name(s)
Returns
TemplateBuilder
Throws
If the base template is not mcp-gateway
Example
Implementation of
TemplateBuilder.betaAddMcpServer

copy()

Copy files or directories into the template.
Parameters
ParameterTypeDescription
srcPathLike | PathLike[]Source path(s)
destPathLikeDestination path
options?objectCopy options
options.forceUpload?true-
options.mode?number-
options.resolveSymlinks?boolean-
options.user?string-
Returns
TemplateBuilder
Example
Implementation of
TemplateBuilder.copy

copyItems()

Copy multiple items with individual options.
Parameters
ParameterTypeDescription
itemsCopyItem[]Array of copy items
Returns
TemplateBuilder
Example
Implementation of
TemplateBuilder.copyItems

fromAWSRegistry()

Start from a Docker image in AWS ECR.
Parameters
ParameterTypeDescription
imagestringFull ECR image path
credentialsobjectAWS credentials
credentials.accessKeyIdstring-
credentials.regionstring-
credentials.secretAccessKeystring-
Returns
TemplateBuilder
Example
Implementation of
TemplateFromImage.fromAWSRegistry

fromBaseImage()

Start from E2B’s default base image (e2bdev/base:latest).
Returns
TemplateBuilder
Example
Implementation of
TemplateFromImage.fromBaseImage

fromDebianImage()

Start from a Debian-based Docker image.
Parameters
ParameterTypeDefault valueDescription
variantstring'stable'Debian variant (default: ‘stable’)
Returns
TemplateBuilder
Example
Implementation of
TemplateFromImage.fromDebianImage

fromDockerfile()

Parse a Dockerfile and convert it to Template SDK format.
Parameters
ParameterTypeDescription
dockerfileContentOrPathstringDockerfile content or path
Returns
TemplateBuilder
Example
Implementation of
TemplateFromImage.fromDockerfile

fromGCPRegistry()

Start from a Docker image in Google Container Registry.
Parameters
ParameterTypeDescription
imagestringFull GCR/GAR image path
credentialsobjectGCP service account credentials
credentials.serviceAccountJSONstring | object-
Returns
TemplateBuilder
Example
Implementation of
TemplateFromImage.fromGCPRegistry

fromImage()

Start from a custom Docker image.
Parameters
ParameterTypeDescription
baseImagestringDocker image name
credentials?objectOptional credentials for private registries
credentials.password?string-
credentials.username?string-
Returns
TemplateBuilder
Example
Implementation of
TemplateFromImage.fromImage

fromNodeImage()

Start from a Node.js-based Docker image.
Parameters
ParameterTypeDefault valueDescription
variantstring'lts'Node.js variant (default: ‘lts’)
Returns
TemplateBuilder
Example
Implementation of
TemplateFromImage.fromNodeImage

fromPythonImage()

Start from a Python-based Docker image.
Parameters
ParameterTypeDefault valueDescription
versionstring'3'Python version (default: ‘3’)
Returns
TemplateBuilder
Example
Implementation of
TemplateFromImage.fromPythonImage

fromTemplate()

Start from an existing E2B template.
Parameters
ParameterTypeDescription
templatestringE2B template ID or alias
Returns
TemplateBuilder
Example
Implementation of
TemplateFromImage.fromTemplate

fromUbuntuImage()

Start from an Ubuntu-based Docker image.
Parameters
ParameterTypeDefault valueDescription
variantstring'lts'Ubuntu variant (default: ‘lts’)
Returns
TemplateBuilder
Example
Implementation of
TemplateFromImage.fromUbuntuImage

gitClone()

Clone a Git repository.
Parameters
ParameterTypeDescription
urlstringRepository URL
path?PathLikeOptional destination path
options?objectClone options
options.branch?string-
options.depth?number-
options.user?string-
Returns
TemplateBuilder
Example
Implementation of
TemplateBuilder.gitClone

makeDir()

Create directories.
Parameters
ParameterTypeDescription
pathPathLike | PathLike[]Directory path(s)
options?objectDirectory options
options.mode?number-
options.user?string-
Returns
TemplateBuilder
Example
Implementation of
TemplateBuilder.makeDir
Create a symbolic link.
Parameters
ParameterTypeDescription
srcPathLikeSource path (target)
destPathLikeDestination path (symlink location)
options?objectSymlink options
options.user?string-
Returns
TemplateBuilder
Example
Implementation of
TemplateBuilder.makeSymlink

npmInstall()

Install Node.js packages using npm.
Parameters
ParameterTypeDescription
packages?string | string[]Package name(s) or undefined for package.json
options?objectInstall options
options.g?boolean-
Returns
TemplateBuilder
Example
Implementation of
TemplateBuilder.npmInstall

pipInstall()

Install Python packages using pip.
Parameters
ParameterTypeDescription
packages?string | string[]Package name(s) or undefined for current directory
options?objectInstall options
options.g?booleanInstall globally as root (default: true). Set to false for user-only installation with —user flag
Returns
TemplateBuilder
Example
Implementation of
TemplateBuilder.pipInstall

remove()

Remove files or directories.
Parameters
ParameterTypeDescription
pathPathLike | PathLike[]Path(s) to remove
options?objectRemove options
options.force?boolean-
options.recursive?boolean-
options.user?string-
Returns
TemplateBuilder
Example
Implementation of
TemplateBuilder.remove

rename()

Rename or move a file or directory.
Parameters
ParameterTypeDescription
srcPathLikeSource path
destPathLikeDestination path
options?objectRename options
options.force?boolean-
options.user?string-
Returns
TemplateBuilder
Example
Implementation of
TemplateBuilder.rename

runCmd()

runCmd(command, options)
Run a shell command.
Parameters
ParameterTypeDescription
commandstringCommand string
options?objectCommand options
options.user?string-
Returns
TemplateBuilder
Example
Implementation of
TemplateBuilder.runCmd
runCmd(commands, options)
Run a shell command.
Parameters
ParameterTypeDescription
commandsstring[]-
options?objectCommand options
options.user?string-
Returns
TemplateBuilder
Example
Implementation of
TemplateBuilder.runCmd

setEnvs()

Set environment variables.
Parameters
ParameterTypeDescription
envsRecord<string, string>Environment variables
Returns
TemplateBuilder
Example
Implementation of
TemplateBuilder.setEnvs

setReadyCmd()

Set or update the ready check command.
Parameters
ParameterTypeDescription
readyCommandstring | ReadyCmdCommand to check readiness
Returns
TemplateFinal
Example
Implementation of
TemplateBuilder.setReadyCmd

setStartCmd()

Set the start command and ready check.
Parameters
ParameterTypeDescription
startCommandstringCommand to run on startup
readyCommandstring | ReadyCmdCommand to check readiness
Returns
TemplateFinal
Example
Implementation of
TemplateBuilder.setStartCmd

setUser()

Set the user for subsequent commands.
Parameters
ParameterTypeDescription
userstringUsername
Returns
TemplateBuilder
Example
Implementation of
TemplateBuilder.setUser

setWorkdir()

Set the working directory.
Parameters
ParameterTypeDescription
workdirPathLikeWorking directory path
Returns
TemplateBuilder
Example
Implementation of
TemplateBuilder.setWorkdir

skipCache()

Skip cache for all subsequent build instructions from this point.
Returns
this
Example
Implementation of
TemplateBuilder.skipCache

build()

Build and deploy a template to E2B infrastructure.
Parameters
ParameterTypeDescription
templateTemplateClassThe template to build
optionsBuildOptionsBuild configuration options
Returns
Promise<void>
Example

toDockerfile()

Convert a template to Dockerfile format. Note: Templates based on other E2B templates cannot be converted to Dockerfile.
Parameters
ParameterTypeDescription
templateTemplateClassThe template to convert
Returns
string Dockerfile string representation
Throws
Error if the template is based on another E2B template

toJSON()

Convert a template to JSON representation.
Parameters
ParameterTypeDefault valueDescription
templateTemplateClassundefinedThe template to convert
computeHashesbooleantrueWhether to compute file hashes for cache invalidation
Returns
Promise<string> JSON string representation of the template

Interfaces

TemplateBuilder

Main builder state for constructing templates. Provides methods for customizing the template environment.

Methods

aptInstall()

Install Debian/Ubuntu packages using apt-get.
Parameters
ParameterTypeDescription
packagesstring | string[]Package name(s)
Returns
TemplateBuilder
Example

betaAddMcpServer()

Install MCP servers using mcp-gateway. Note: Requires a base image with mcp-gateway pre-installed (e.g., mcp-gateway).
Parameters
ParameterTypeDescription
serverskeyof McpServer | keyof McpServer[]MCP server name(s)
Returns
TemplateBuilder
Throws
If the base template is not mcp-gateway
Example

copy()

Copy files or directories into the template.
Parameters
ParameterTypeDescription
srcPathLike | PathLike[]Source path(s)
destPathLikeDestination path
options?objectCopy options
options.forceUpload?true-
options.mode?number-
options.resolveSymlinks?boolean-
options.user?string-
Returns
TemplateBuilder
Example

copyItems()

Copy multiple items with individual options.
Parameters
ParameterTypeDescription
itemsCopyItem[]Array of copy items
Returns
TemplateBuilder
Example

gitClone()

Clone a Git repository.
Parameters
ParameterTypeDescription
urlstringRepository URL
path?PathLikeOptional destination path
options?objectClone options
options.branch?string-
options.depth?number-
options.user?string-
Returns
TemplateBuilder
Example

makeDir()

Create directories.
Parameters
ParameterTypeDescription
pathPathLike | PathLike[]Directory path(s)
options?objectDirectory options
options.mode?number-
options.user?string-
Returns
TemplateBuilder
Example
Create a symbolic link.
Parameters
ParameterTypeDescription
srcPathLikeSource path (target)
destPathLikeDestination path (symlink location)
options?objectSymlink options
options.user?string-
Returns
TemplateBuilder
Example

npmInstall()

Install Node.js packages using npm.
Parameters
ParameterTypeDescription
packages?string | string[]Package name(s) or undefined for package.json
options?objectInstall options
options.g?boolean-
Returns
TemplateBuilder
Example

pipInstall()

Install Python packages using pip.
Parameters
ParameterTypeDescription
packages?string | string[]Package name(s) or undefined for current directory
options?objectInstall options
options.g?booleanInstall globally as root (default: true). Set to false for user-only installation with —user flag
Returns
TemplateBuilder
Example

remove()

Remove files or directories.
Parameters
ParameterTypeDescription
pathPathLike | PathLike[]Path(s) to remove
options?objectRemove options
options.force?boolean-
options.recursive?boolean-
options.user?string-
Returns
TemplateBuilder
Example

rename()

Rename or move a file or directory.
Parameters
ParameterTypeDescription
srcPathLikeSource path
destPathLikeDestination path
options?objectRename options
options.force?boolean-
options.user?string-
Returns
TemplateBuilder
Example

runCmd()

runCmd(command, options)
Run a shell command.
Parameters
ParameterTypeDescription
commandstringCommand string
options?objectCommand options
options.user?string-
Returns
TemplateBuilder
Example
runCmd(commands, options)
Run multiple shell commands.
Parameters
ParameterTypeDescription
commandsstring[]Array of command strings
options?objectCommand options
options.user?string-
Returns
TemplateBuilder
runCmd(commandOrCommands, options)
Run command(s).
Parameters
ParameterTypeDescription
commandOrCommandsstring | string[]Command or commands
options?objectCommand options
options.user?string-
Returns
TemplateBuilder

setEnvs()

Set environment variables.
Parameters
ParameterTypeDescription
envsRecord<string, string>Environment variables
Returns
TemplateBuilder
Example

setReadyCmd()

Set or update the ready check command.
Parameters
ParameterTypeDescription
readyCommandstring | ReadyCmdCommand to check readiness
Returns
TemplateFinal
Example

setStartCmd()

Set the start command and ready check.
Parameters
ParameterTypeDescription
startCommandstringCommand to run on startup
readyCommandstring | ReadyCmdCommand to check readiness
Returns
TemplateFinal
Example

setUser()

Set the user for subsequent commands.
Parameters
ParameterTypeDescription
userstringUsername
Returns
TemplateBuilder
Example

setWorkdir()

Set the working directory.
Parameters
ParameterTypeDescription
workdirPathLikeWorking directory path
Returns
TemplateBuilder
Example

skipCache()

Skip cache for all subsequent build instructions from this point.
Returns
this
Example

Type Aliases

BuildOptions

Options for building a template with authentication.

Type declaration

NameTypeDescription
apiKey?stringE2B API key for authentication.
domain?stringDomain of the E2B API.

CopyItem

Configuration for a single file/directory copy operation.

Type declaration

NameType
destPathLike
forceUpload?true
mode?number
resolveSymlinks?boolean
srcPathLike | PathLike[]
user?string

McpServerName

MCP server names that can be installed.

TemplateClass

Type representing a template in any state (builder or final).

Functions

Template()

Create a new E2B template builder instance.

Parameters

ParameterTypeDescription
options?TemplateOptionsOptional configuration for the template builder

Returns

TemplateFromImage A new template builder instance

Example