TemplateBase
Base class for building E2B sandbox templates.Implements
TemplateFromImageTemplateBuilderTemplateFinal
Constructors
Parameters
| Parameter | Type |
|---|---|
options? | TemplateOptions |
Returns
TemplateBase
Methods
addMcpServer()
Parameters
| Parameter | Type | Description |
|---|---|---|
servers | keyof McpServer | keyof McpServer[] | MCP server name(s) |
Returns
TemplateBuilder
Throws
If the base template is not mcp-gatewayExample
Implementation of
TemplateBuilder.addMcpServer
aptInstall()
Parameters
| Parameter | Type | Description |
|---|---|---|
packages | string | string[] | Package name(s) |
options? | object | - |
options.noInstallRecommends? | boolean | - |
Returns
TemplateBuilder
Example
Implementation of
TemplateBuilder.aptInstall
betaDevContainerPrebuild()
Parameters
| Parameter | Type | Description |
|---|---|---|
devcontainerDirectory | string | Path to the devcontainer directory |
Returns
TemplateBuilder
Example
Implementation of
TemplateBuilder.betaDevContainerPrebuild
betaSetDevContainerStart()
Parameters
| Parameter | Type | Description |
|---|---|---|
devcontainerDirectory | string | Path to the devcontainer directory |
Returns
TemplateFinal
Example
Implementation of
TemplateBuilder.betaSetDevContainerStart
bunInstall()
Parameters
| Parameter | Type | Description |
|---|---|---|
packages? | string | string[] | Package name(s) or undefined for package.json |
options? | object | Install options |
options.dev? | boolean | - |
options.g? | boolean | - |
Returns
TemplateBuilder
Example
Implementation of
TemplateBuilder.bunInstall
copy()
Parameters
| Parameter | Type | Description |
|---|---|---|
src | PathLike | PathLike[] | Source path(s) |
dest | PathLike | Destination path |
options? | object | Copy options |
options.forceUpload? | true | - |
options.mode? | number | - |
options.resolveSymlinks? | boolean | - |
options.user? | string | - |
Returns
TemplateBuilder
Example
Implementation of
TemplateBuilder.copy
copyItems()
Parameters
| Parameter | Type | Description |
|---|---|---|
items | CopyItem[] | Array of copy items |
Returns
TemplateBuilder
Example
Implementation of
TemplateBuilder.copyItems
fromAWSRegistry()
Parameters
| Parameter | Type | Description |
|---|---|---|
image | string | Full ECR image path |
credentials | object | AWS credentials |
credentials.accessKeyId | string | - |
credentials.region | string | - |
credentials.secretAccessKey | string | - |
Returns
TemplateBuilder
Example
Implementation of
TemplateFromImage.fromAWSRegistry
fromBaseImage()
Returns
TemplateBuilder
Example
Implementation of
TemplateFromImage.fromBaseImage
fromBunImage()
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
variant | string | 'latest' | Bun variant (default: ‘latest’) |
Returns
TemplateBuilder
Example
Implementation of
TemplateFromImage.fromBunImage
fromDebianImage()
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
variant | string | 'stable' | Debian variant (default: ‘stable’) |
Returns
TemplateBuilder
Example
Implementation of
TemplateFromImage.fromDebianImage
fromDockerfile()
Parameters
| Parameter | Type | Description |
|---|---|---|
dockerfileContentOrPath | string | Dockerfile content or path |
Returns
TemplateBuilder
Example
Implementation of
TemplateFromImage.fromDockerfile
fromGCPRegistry()
Parameters
| Parameter | Type | Description |
|---|---|---|
image | string | Full GCR/GAR image path |
credentials | object | GCP service account credentials |
credentials.serviceAccountJSON | string | object | - |
Returns
TemplateBuilder
Example
Implementation of
TemplateFromImage.fromGCPRegistry
fromImage()
Parameters
| Parameter | Type | Description |
|---|---|---|
baseImage | string | Docker image name |
credentials? | object | Optional credentials for private registries |
credentials.password? | string | - |
credentials.username? | string | - |
Returns
TemplateBuilder
Example
Implementation of
TemplateFromImage.fromImage
fromNodeImage()
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
variant | string | 'lts' | Node.js variant (default: ‘lts’) |
Returns
TemplateBuilder
Example
Implementation of
TemplateFromImage.fromNodeImage
fromPythonImage()
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
version | string | '3' | Python version (default: ‘3’) |
Returns
TemplateBuilder
Example
Implementation of
TemplateFromImage.fromPythonImage
fromTemplate()
Parameters
| Parameter | Type | Description |
|---|---|---|
template | string | E2B template ID or alias |
Returns
TemplateBuilder
Example
Implementation of
TemplateFromImage.fromTemplate
fromUbuntuImage()
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
variant | string | 'latest' | Ubuntu variant (default: ‘latest’) |
Returns
TemplateBuilder
Example
Implementation of
TemplateFromImage.fromUbuntuImage
gitClone()
Parameters
| Parameter | Type | Description |
|---|---|---|
url | string | Repository URL |
path? | PathLike | Optional destination path |
options? | object | Clone options |
options.branch? | string | - |
options.depth? | number | - |
options.user? | string | - |
Returns
TemplateBuilder
Example
Implementation of
TemplateBuilder.gitClone
makeDir()
Parameters
| Parameter | Type | Description |
|---|---|---|
path | PathLike | PathLike[] | Directory path(s) |
options? | object | Directory options |
options.mode? | number | - |
options.user? | string | - |
Returns
TemplateBuilder
Example
Implementation of
TemplateBuilder.makeDir
makeSymlink()
Parameters
| Parameter | Type | Description |
|---|---|---|
src | PathLike | Source path (target) |
dest | PathLike | Destination path (symlink location) |
options? | object | Symlink options |
options.force? | boolean | - |
options.user? | string | - |
Returns
TemplateBuilder
Example
Implementation of
TemplateBuilder.makeSymlink
npmInstall()
Parameters
| Parameter | Type | Description |
|---|---|---|
packages? | string | string[] | Package name(s) or undefined for package.json |
options? | object | Install options |
options.dev? | boolean | - |
options.g? | boolean | - |
Returns
TemplateBuilder
Example
Implementation of
TemplateBuilder.npmInstall
pipInstall()
Parameters
| Parameter | Type | Description |
|---|---|---|
packages? | string | string[] | Package name(s) or undefined for current directory |
options? | object | Install options |
options.g? | boolean | Install globally as root (default: true). Set to false for user-only installation with —user flag |
Returns
TemplateBuilder
Example
Implementation of
TemplateBuilder.pipInstall
remove()
Parameters
| Parameter | Type | Description |
|---|---|---|
path | PathLike | PathLike[] | Path(s) to remove |
options? | object | Remove options |
options.force? | boolean | - |
options.recursive? | boolean | - |
options.user? | string | - |
Returns
TemplateBuilder
Example
Implementation of
TemplateBuilder.remove
rename()
Parameters
| Parameter | Type | Description |
|---|---|---|
src | PathLike | Source path |
dest | PathLike | Destination path |
options? | object | Rename options |
options.force? | boolean | - |
options.user? | string | - |
Returns
TemplateBuilder
Example
Implementation of
TemplateBuilder.rename
runCmd()
runCmd(command, options)
Parameters
| Parameter | Type | Description |
|---|---|---|
command | string | Command string |
options? | object | Command options |
options.user? | string | - |
Returns
TemplateBuilder
Example
Implementation of
TemplateBuilder.runCmd
runCmd(commands, options)
Parameters
| Parameter | Type | Description |
|---|---|---|
commands | string[] | - |
options? | object | Command options |
options.user? | string | - |
Returns
TemplateBuilder
Example
Implementation of
TemplateBuilder.runCmd
setEnvs()
Parameters
| Parameter | Type | Description |
|---|---|---|
envs | Record<string, string> | Environment variables |
Returns
TemplateBuilder
Example
Implementation of
TemplateBuilder.setEnvs
setReadyCmd()
Parameters
| Parameter | Type | Description |
|---|---|---|
readyCommand | string | ReadyCmd | Command to check readiness |
Returns
TemplateFinal
Example
Implementation of
TemplateBuilder.setReadyCmd
setStartCmd()
Parameters
| Parameter | Type | Description |
|---|---|---|
startCommand | string | Command to run on startup |
readyCommand | string | ReadyCmd | Command to check readiness |
Returns
TemplateFinal
Example
Implementation of
TemplateBuilder.setStartCmd
setUser()
Parameters
| Parameter | Type | Description |
|---|---|---|
user | string | Username |
Returns
TemplateBuilder
Example
Implementation of
TemplateBuilder.setUser
setWorkdir()
Parameters
| Parameter | Type | Description |
|---|---|---|
workdir | PathLike | Working directory path |
Returns
TemplateBuilder
Example
Implementation of
TemplateBuilder.setWorkdir
skipCache()
Returns
this
Example
Implementation of
TemplateBuilder.skipCache
build()
Parameters
| Parameter | Type | Description |
|---|---|---|
template | TemplateClass | The template to build |
options | BuildOptions | Build configuration options |
Returns
Promise<BuildInfo>
Example
buildInBackground()
Parameters
| Parameter | Type | Description |
|---|---|---|
template | TemplateClass | The template to build |
options | BuildOptions | Build configuration options |
Returns
Promise<BuildInfo>
Example
getBuildStatus()
Parameters
| Parameter | Type | Description |
|---|---|---|
data | Pick<BuildInfo, "templateId" | "buildId"> | Build identifiers |
options? | GetBuildStatusOptions | Authentication options |
Returns
Promise<object>
| Name | Type | Description |
|---|---|---|
buildID | string | Description Identifier of the build |
logEntries | object[] | Description Build logs structured Default [] |
logs | string[] | Description Build logs Default [] |
reason? | object | - |
reason.logEntries? | object[] | Description Log entries related to the status reason Default [] |
reason.message | string | Description Message with the status reason, currently reporting only for error status |
reason.step? | string | Description Step that failed |
status | "error" | "ready" | "building" | "waiting" | - |
templateID | string | Description Identifier of the template |
Example
toDockerfile()
Parameters
| Parameter | Type | Description |
|---|---|---|
template | TemplateClass | The template to convert |
Returns
string
Dockerfile string representation
Throws
Error if the template is based on another E2B templatetoJSON()
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
template | TemplateClass | undefined | The template to convert |
computeHashes | boolean | true | Whether 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
addMcpServer()
Parameters
| Parameter | Type | Description |
|---|---|---|
servers | keyof McpServer | keyof McpServer[] | MCP server name(s) |
Returns
TemplateBuilder
Throws
If the base template is not mcp-gatewayExample
aptInstall()
Parameters
| Parameter | Type | Description |
|---|---|---|
packages | string | string[] | Package name(s) |
options? | object | - |
options.noInstallRecommends? | boolean | - |
Returns
TemplateBuilder
Example
betaDevContainerPrebuild()
Parameters
| Parameter | Type | Description |
|---|---|---|
devcontainerDirectory | string | Path to the devcontainer directory |
Returns
TemplateBuilder
Example
betaSetDevContainerStart()
Parameters
| Parameter | Type | Description |
|---|---|---|
devcontainerDirectory | string | Path to the devcontainer directory |
Returns
TemplateFinal
Example
bunInstall()
Parameters
| Parameter | Type | Description |
|---|---|---|
packages? | string | string[] | Package name(s) or undefined for package.json |
options? | object | Install options |
options.dev? | boolean | - |
options.g? | boolean | - |
Returns
TemplateBuilder
Example
copy()
Parameters
| Parameter | Type | Description |
|---|---|---|
src | PathLike | PathLike[] | Source path(s) |
dest | PathLike | Destination path |
options? | object | Copy options |
options.forceUpload? | true | - |
options.mode? | number | - |
options.resolveSymlinks? | boolean | - |
options.user? | string | - |
Returns
TemplateBuilder
Example
copyItems()
Parameters
| Parameter | Type | Description |
|---|---|---|
items | CopyItem[] | Array of copy items |
Returns
TemplateBuilder
Example
gitClone()
Parameters
| Parameter | Type | Description |
|---|---|---|
url | string | Repository URL |
path? | PathLike | Optional destination path |
options? | object | Clone options |
options.branch? | string | - |
options.depth? | number | - |
options.user? | string | - |
Returns
TemplateBuilder
Example
makeDir()
Parameters
| Parameter | Type | Description |
|---|---|---|
path | PathLike | PathLike[] | Directory path(s) |
options? | object | Directory options |
options.mode? | number | - |
options.user? | string | - |
Returns
TemplateBuilder
Example
makeSymlink()
Parameters
| Parameter | Type | Description |
|---|---|---|
src | PathLike | Source path (target) |
dest | PathLike | Destination path (symlink location) |
options? | object | Symlink options |
options.force? | boolean | - |
options.user? | string | - |
Returns
TemplateBuilder
Example
npmInstall()
Parameters
| Parameter | Type | Description |
|---|---|---|
packages? | string | string[] | Package name(s) or undefined for package.json |
options? | object | Install options |
options.dev? | boolean | - |
options.g? | boolean | - |
Returns
TemplateBuilder
Example
pipInstall()
Parameters
| Parameter | Type | Description |
|---|---|---|
packages? | string | string[] | Package name(s) or undefined for current directory |
options? | object | Install options |
options.g? | boolean | Install globally as root (default: true). Set to false for user-only installation with —user flag |
Returns
TemplateBuilder
Example
remove()
Parameters
| Parameter | Type | Description |
|---|---|---|
path | PathLike | PathLike[] | Path(s) to remove |
options? | object | Remove options |
options.force? | boolean | - |
options.recursive? | boolean | - |
options.user? | string | - |
Returns
TemplateBuilder
Example
rename()
Parameters
| Parameter | Type | Description |
|---|---|---|
src | PathLike | Source path |
dest | PathLike | Destination path |
options? | object | Rename options |
options.force? | boolean | - |
options.user? | string | - |
Returns
TemplateBuilder
Example
runCmd()
runCmd(command, options)
Parameters
| Parameter | Type | Description |
|---|---|---|
command | string | Command string |
options? | object | Command options |
options.user? | string | - |
Returns
TemplateBuilder
Example
runCmd(commands, options)
Parameters
| Parameter | Type | Description |
|---|---|---|
commands | string[] | Array of command strings |
options? | object | Command options |
options.user? | string | - |
Returns
TemplateBuilder
runCmd(commandOrCommands, options)
Parameters
| Parameter | Type | Description |
|---|---|---|
commandOrCommands | string | string[] | Command or commands |
options? | object | Command options |
options.user? | string | - |
Returns
TemplateBuilder
setEnvs()
Parameters
| Parameter | Type | Description |
|---|---|---|
envs | Record<string, string> | Environment variables |
Returns
TemplateBuilder
Example
setReadyCmd()
Parameters
| Parameter | Type | Description |
|---|---|---|
readyCommand | string | ReadyCmd | Command to check readiness |
Returns
TemplateFinal
Example
setStartCmd()
Parameters
| Parameter | Type | Description |
|---|---|---|
startCommand | string | Command to run on startup |
readyCommand | string | ReadyCmd | Command to check readiness |
Returns
TemplateFinal
Example
setUser()
Parameters
| Parameter | Type | Description |
|---|---|---|
user | string | Username |
Returns
TemplateBuilder
Example
setWorkdir()
Parameters
| Parameter | Type | Description |
|---|---|---|
workdir | PathLike | Working directory path |
Returns
TemplateBuilder
Example
skipCache()
Returns
this
Example
Type Aliases
BuildInfo
Type declaration
| Name | Type |
|---|---|
alias | string |
buildId | string |
templateId | string |
BuildOptions
CopyItem
Type declaration
| Name | Type |
|---|---|
dest | PathLike |
forceUpload? | true |
mode? | number |
resolveSymlinks? | boolean |
src | PathLike | PathLike[] |
user? | string |
GetBuildStatusOptions
Type declaration
| Name | Type |
|---|---|
logsOffset? | number |
McpServerName
TemplateClass
Functions
Template()
Parameters
| Parameter | Type | Description |
|---|---|---|
options? | TemplateOptions | Optional configuration for the template builder |
Returns
TemplateFromImage
A new template builder instance