# Template (/v2.29.1/template)

<!-- agent-signals: reading_time_min: 33 · est_tokens: 17174 · updated: 2026-07-30 -->
Related: [Errors](/v2.29.1/errors.md), [Sandbox](/v2.29.1/sandbox.md), [Sandbox Commands](/v2.29.1/sandbox-commands.md), [Sandbox Filesystem](/v2.29.1/sandbox-filesystem.md), [Template Logger](/v2.29.1/template-logger.md), [Template Readycmd](/v2.29.1/template-readycmd.md)

### TemplateBase [#templatebase]

Base class for building E2B sandbox templates.

#### Implements [#implements]

* `TemplateFromImage`
* `TemplateBuilder`
* `TemplateFinal`

#### Constructors [#constructors]

```ts
new TemplateBase(options?: TemplateOptions): TemplateBase
```

###### Parameters [#parameters]

| Parameter  | Type              |
| ---------- | ----------------- |
| `options`? | `TemplateOptions` |

###### Returns [#returns]

`TemplateBase`

#### Methods [#methods]

### addMcpServer() [#addmcpserver]

```ts
addMcpServer(servers: keyof McpServer | keyof McpServer[]): TemplateBuilder
```

Install MCP servers using mcp-gateway.
Note: Requires a base image with mcp-gateway pre-installed (e.g., mcp-gateway).

###### Parameters [#parameters-1]

| Parameter | Type                                  | Description        |
| --------- | ------------------------------------- | ------------------ |
| `servers` | keyof McpServer \| keyof McpServer\[] | MCP server name(s) |

###### Returns [#returns-1]

`TemplateBuilder`

###### Throws [#throws]

If the base template is not mcp-gateway

###### Example [#example]

```ts
template.addMcpServer('exa')
template.addMcpServer(['brave', 'firecrawl', 'duckduckgo'])
```

###### Implementation of [#implementation-of]

`TemplateBuilder`.`addMcpServer`

### aptInstall() [#aptinstall]

```ts
aptInstall(packages: string | string[], options?: object): TemplateBuilder
```

Install Debian/Ubuntu packages using apt-get.

###### Parameters [#parameters-2]

| Parameter                      | Type                                                            | Description     |
| ------------------------------ | --------------------------------------------------------------- | --------------- |
| `packages`                     | `string` \| `string`\[]                                         | Package name(s) |
| `options`?                     | \{ `fixMissing`: `boolean`; `noInstallRecommends`: `boolean`; } | -               |
| `options.fixMissing`?          | `boolean`                                                       | -               |
| `options.noInstallRecommends`? | `boolean`                                                       | -               |

###### Returns [#returns-2]

`TemplateBuilder`

###### Example [#example-1]

```ts
template.aptInstall('vim')
template.aptInstall(['git', 'curl', 'wget'])
template.aptInstall(['vim'], { noInstallRecommends: true })
template.aptInstall(['vim'], { fixMissing: true })
```

###### Implementation of [#implementation-of-1]

`TemplateBuilder`.`aptInstall`

### betaDevContainerPrebuild() [#betadevcontainerprebuild]

```ts
betaDevContainerPrebuild(devcontainerDirectory: string): TemplateBuilder
```

Prebuild a devcontainer from the specified directory.

###### Parameters [#parameters-3]

| Parameter               | Type     | Description                        |
| ----------------------- | -------- | ---------------------------------- |
| `devcontainerDirectory` | `string` | Path to the devcontainer directory |

###### Returns [#returns-3]

`TemplateBuilder`

###### Example [#example-2]

```ts
template
 .gitClone('https://myrepo.com/project.git', '/my-devcontainer')
 .betaDevContainerPrebuild('/my-devcontainer')
```

###### Implementation of [#implementation-of-2]

`TemplateBuilder`.`betaDevContainerPrebuild`

### betaSetDevContainerStart() [#betasetdevcontainerstart]

```ts
betaSetDevContainerStart(devcontainerDirectory: string): TemplateFinal
```

Start a devcontainer from the specified directory.

###### Parameters [#parameters-4]

| Parameter               | Type     | Description                        |
| ----------------------- | -------- | ---------------------------------- |
| `devcontainerDirectory` | `string` | Path to the devcontainer directory |

###### Returns [#returns-4]

`TemplateFinal`

###### Example [#example-3]

```ts
template
 .gitClone('https://myrepo.com/project.git', '/my-devcontainer')
 .startDevcontainer('/my-devcontainer')

// Prebuild and start
template
 .gitClone('https://myrepo.com/project.git', '/my-devcontainer')
 .betaDevContainerPrebuild('/my-devcontainer')
 // Other instructions...
 .betaSetDevContainerStart('/my-devcontainer')
```

###### Implementation of [#implementation-of-3]

`TemplateBuilder`.`betaSetDevContainerStart`

### bunInstall() [#buninstall]

```ts
bunInstall(packages?: string | string[], options?: object): TemplateBuilder
```

Install Bun packages using bun.

###### Parameters [#parameters-5]

| Parameter      | Type                                   | Description                                   |
| -------------- | -------------------------------------- | --------------------------------------------- |
| `packages`?    | `string` \| `string`\[]                | Package name(s) or undefined for package.json |
| `options`?     | \{ `dev`: `boolean`; `g`: `boolean`; } | Install options                               |
| `options.dev`? | `boolean`                              | -                                             |
| `options.g`?   | `boolean`                              | -                                             |

###### Returns [#returns-5]

`TemplateBuilder`

###### Example [#example-4]

```ts
template.bunInstall('express')
template.bunInstall(['lodash', 'axios'])
template.bunInstall('tsx', { g: true })
template.bunInstall('typescript', { dev: true })
template.bunInstall()  // Installs from package.json
```

###### Implementation of [#implementation-of-4]

`TemplateBuilder`.`bunInstall`

### copy() [#copy]

```ts
copy(
   src: PathLike | PathLike[], 
   dest: PathLike, 
   options?: object): TemplateBuilder
```

Copy files or directories into the template.

###### Parameters [#parameters-6]

| Parameter                  | Type                                                                                          | Description      |
| -------------------------- | --------------------------------------------------------------------------------------------- | ---------------- |
| `src`                      | `PathLike` \| `PathLike`\[]                                                                   | Source path(s)   |
| `dest`                     | `PathLike`                                                                                    | Destination path |
| `options`?                 | \{ `forceUpload`: `true`; `mode`: `number`; `resolveSymlinks`: `boolean`; `user`: `string`; } | Copy options     |
| `options.forceUpload`?     | `true`                                                                                        | -                |
| `options.mode`?            | `number`                                                                                      | -                |
| `options.resolveSymlinks`? | `boolean`                                                                                     | -                |
| `options.user`?            | `string`                                                                                      | -                |

###### Returns [#returns-6]

`TemplateBuilder`

###### Example [#example-5]

```ts
template.copy('requirements.txt', '/home/user/')
template.copy(['app.ts', 'config.ts'], '/app/', { mode: 0o755 })
```

###### Implementation of [#implementation-of-5]

`TemplateBuilder`.`copy`

### copyItems() [#copyitems]

```ts
copyItems(items: CopyItem[]): TemplateBuilder
```

Copy multiple items with individual options.

###### Parameters [#parameters-7]

| Parameter | Type          | Description         |
| --------- | ------------- | ------------------- |
| `items`   | `CopyItem`\[] | Array of copy items |

###### Returns [#returns-7]

`TemplateBuilder`

###### Example [#example-6]

```ts
template.copyItems([
  { src: 'app.ts', dest: '/app/' },
  { src: 'config.ts', dest: '/app/', mode: 0o644 }
])
```

###### Implementation of [#implementation-of-6]

`TemplateBuilder`.`copyItems`

### fromAWSRegistry() [#fromawsregistry]

```ts
fromAWSRegistry(image: string, credentials: object): TemplateBuilder
```

Start from a Docker image in AWS ECR.

###### Parameters [#parameters-8]

| Parameter                     | Type                                                                           | Description         |
| ----------------------------- | ------------------------------------------------------------------------------ | ------------------- |
| `image`                       | `string`                                                                       | Full ECR image path |
| `credentials`                 | \{ `accessKeyId`: `string`; `region`: `string`; `secretAccessKey`: `string`; } | AWS credentials     |
| `credentials.accessKeyId`     | `string`                                                                       | -                   |
| `credentials.region`          | `string`                                                                       | -                   |
| `credentials.secretAccessKey` | `string`                                                                       | -                   |

###### Returns [#returns-8]

`TemplateBuilder`

###### Example [#example-7]

```ts
Template().fromAWSRegistry(
  '123456789.dkr.ecr.us-west-2.amazonaws.com/myimage:latest',
  {
    accessKeyId: 'AKIA...',
    secretAccessKey: '...',
    region: 'us-west-2'
  }
)
```

###### Implementation of [#implementation-of-7]

```ts
TemplateFromImage.fromAWSRegistry
```

### fromBaseImage() [#frombaseimage]

```ts
fromBaseImage(): TemplateBuilder
```

Start from E2B's default base image (e2bdev/base:latest).

###### Returns [#returns-9]

`TemplateBuilder`

###### Example [#example-8]

```ts
Template().fromBaseImage()
```

###### Implementation of [#implementation-of-8]

```ts
TemplateFromImage.fromBaseImage
```

### fromBunImage() [#frombunimage]

```ts
fromBunImage(variant: string): TemplateBuilder
```

Start from a Bun-based Docker image.

###### Parameters [#parameters-9]

| Parameter | Type     | Default value | Description                     |
| --------- | -------- | ------------- | ------------------------------- |
| `variant` | `string` | `'latest'`    | Bun variant (default: 'latest') |

###### Returns [#returns-10]

`TemplateBuilder`

###### Example [#example-9]

```ts
Template().fromBunImage('1.3')
```

###### Implementation of [#implementation-of-9]

```ts
TemplateFromImage.fromBunImage
```

### fromDebianImage() [#fromdebianimage]

```ts
fromDebianImage(variant: string): TemplateBuilder
```

Start from a Debian-based Docker image.

###### Parameters [#parameters-10]

| Parameter | Type     | Default value | Description                        |
| --------- | -------- | ------------- | ---------------------------------- |
| `variant` | `string` | `'stable'`    | Debian variant (default: 'stable') |

###### Returns [#returns-11]

`TemplateBuilder`

###### Example [#example-10]

```ts
Template().fromDebianImage('bookworm')
```

###### Implementation of [#implementation-of-10]

```ts
TemplateFromImage.fromDebianImage
```

### fromDockerfile() [#fromdockerfile]

```ts
fromDockerfile(dockerfileContentOrPath: string): TemplateBuilder
```

Parse a Dockerfile and convert it to Template SDK format.

###### Parameters [#parameters-11]

| Parameter                 | Type     | Description                |
| ------------------------- | -------- | -------------------------- |
| `dockerfileContentOrPath` | `string` | Dockerfile content or path |

###### Returns [#returns-12]

`TemplateBuilder`

###### Example [#example-11]

```ts
Template().fromDockerfile('Dockerfile')
Template().fromDockerfile('FROM python:3\nRUN pip install numpy')
```

###### Implementation of [#implementation-of-11]

```ts
TemplateFromImage.fromDockerfile
```

### fromGCPRegistry() [#fromgcpregistry]

```ts
fromGCPRegistry(image: string, credentials: object): TemplateBuilder
```

Start from a Docker image in Google Container Registry.

###### Parameters [#parameters-12]

| Parameter                        | Type                                             | Description                     |
| -------------------------------- | ------------------------------------------------ | ------------------------------- |
| `image`                          | `string`                                         | Full GCR/GAR image path         |
| `credentials`                    | \{ `serviceAccountJSON`: `string` \| `object`; } | GCP service account credentials |
| `credentials.serviceAccountJSON` | `string` \| `object`                             | -                               |

###### Returns [#returns-13]

`TemplateBuilder`

###### Example [#example-12]

```ts
Template().fromGCPRegistry(
  'gcr.io/myproject/myimage:latest',
  { serviceAccountJSON: 'path/to/service-account.json' }
)
```

###### Implementation of [#implementation-of-12]

```ts
TemplateFromImage.fromGCPRegistry
```

### fromImage() [#fromimage]

```ts
fromImage(baseImage: string, credentials?: object): TemplateBuilder
```

Start from a custom Docker image.

###### Parameters [#parameters-13]

| Parameter               | Type                                             | Description                                 |
| ----------------------- | ------------------------------------------------ | ------------------------------------------- |
| `baseImage`             | `string`                                         | Docker image name                           |
| `credentials`?          | \{ `password`: `string`; `username`: `string`; } | Optional credentials for private registries |
| `credentials.password`? | `string`                                         | -                                           |
| `credentials.username`? | `string`                                         | -                                           |

###### Returns [#returns-14]

`TemplateBuilder`

###### Example [#example-13]

```ts
Template().fromImage('python:3')

// With credentials (optional)
Template().fromImage('myregistry.com/myimage:latest', {
  username: 'user',
  password: 'pass'
})
```

###### Implementation of [#implementation-of-13]

```ts
TemplateFromImage.fromImage
```

### fromNodeImage() [#fromnodeimage]

```ts
fromNodeImage(variant: string): TemplateBuilder
```

Start from a Node.js-based Docker image.

###### Parameters [#parameters-14]

| Parameter | Type     | Default value | Description                      |
| --------- | -------- | ------------- | -------------------------------- |
| `variant` | `string` | `'lts'`       | Node.js variant (default: 'lts') |

###### Returns [#returns-15]

`TemplateBuilder`

###### Example [#example-14]

```ts
Template().fromNodeImage('24')
```

###### Implementation of [#implementation-of-14]

```ts
TemplateFromImage.fromNodeImage
```

### fromPythonImage() [#frompythonimage]

```ts
fromPythonImage(version: string): TemplateBuilder
```

Start from a Python-based Docker image.

###### Parameters [#parameters-15]

| Parameter | Type     | Default value | Description                   |
| --------- | -------- | ------------- | ----------------------------- |
| `version` | `string` | `'3'`         | Python version (default: '3') |

###### Returns [#returns-16]

`TemplateBuilder`

###### Example [#example-15]

```ts
Template().fromPythonImage('3')
```

###### Implementation of [#implementation-of-15]

```ts
TemplateFromImage.fromPythonImage
```

### fromTemplate() [#fromtemplate]

```ts
fromTemplate(template: string): TemplateBuilder
```

Start from an existing E2B template.

###### Parameters [#parameters-16]

| Parameter  | Type     | Description              |
| ---------- | -------- | ------------------------ |
| `template` | `string` | E2B template ID or alias |

###### Returns [#returns-17]

`TemplateBuilder`

###### Example [#example-16]

```ts
Template().fromTemplate('my-base-template')
```

###### Implementation of [#implementation-of-16]

```ts
TemplateFromImage.fromTemplate
```

### fromUbuntuImage() [#fromubuntuimage]

```ts
fromUbuntuImage(variant: string): TemplateBuilder
```

Start from an Ubuntu-based Docker image.

###### Parameters [#parameters-17]

| Parameter | Type     | Default value | Description                        |
| --------- | -------- | ------------- | ---------------------------------- |
| `variant` | `string` | `'latest'`    | Ubuntu variant (default: 'latest') |

###### Returns [#returns-18]

`TemplateBuilder`

###### Example [#example-17]

```ts
Template().fromUbuntuImage('24.04')
```

###### Implementation of [#implementation-of-17]

```ts
TemplateFromImage.fromUbuntuImage
```

### gitClone() [#gitclone]

```ts
gitClone(
   url: string, 
   path?: PathLike, 
   options?: object): TemplateBuilder
```

Clone a Git repository.

###### Parameters [#parameters-18]

| Parameter         | Type                                                          | Description               |
| ----------------- | ------------------------------------------------------------- | ------------------------- |
| `url`             | `string`                                                      | Repository URL            |
| `path`?           | `PathLike`                                                    | Optional destination path |
| `options`?        | \{ `branch`: `string`; `depth`: `number`; `user`: `string`; } | Clone options             |
| `options.branch`? | `string`                                                      | -                         |
| `options.depth`?  | `number`                                                      | -                         |
| `options.user`?   | `string`                                                      | -                         |

###### Returns [#returns-19]

`TemplateBuilder`

###### Example [#example-18]

```ts
template.gitClone('https://github.com/user/repo.git', '/app/repo')
template.gitClone('https://github.com/user/repo.git', undefined, {
  branch: 'main',
  depth: 1
})
template.gitClone('https://github.com/user/repo.git', '/app/repo', {
  user: 'root'
})
```

###### Implementation of [#implementation-of-18]

`TemplateBuilder`.`gitClone`

### makeDir() [#makedir]

```ts
makeDir(path: PathLike | PathLike[], options?: object): TemplateBuilder
```

Create directories.

###### Parameters [#parameters-19]

| Parameter       | Type                                     | Description       |
| --------------- | ---------------------------------------- | ----------------- |
| `path`          | `PathLike` \| `PathLike`\[]              | Directory path(s) |
| `options`?      | \{ `mode`: `number`; `user`: `string`; } | Directory options |
| `options.mode`? | `number`                                 | -                 |
| `options.user`? | `string`                                 | -                 |

###### Returns [#returns-20]

`TemplateBuilder`

###### Example [#example-19]

```ts
template.makeDir('/app/data', { mode: 0o755 })
template.makeDir(['/app/logs', '/app/cache'])
template.makeDir('/app/data', { mode: 0o755, user: 'root' })
```

###### Implementation of [#implementation-of-19]

`TemplateBuilder`.`makeDir`

### makeSymlink() [#makesymlink]

```ts
makeSymlink(
   src: PathLike, 
   dest: PathLike, 
   options?: object): TemplateBuilder
```

Create a symbolic link.

###### Parameters [#parameters-20]

| Parameter        | Type                                       | Description                         |
| ---------------- | ------------------------------------------ | ----------------------------------- |
| `src`            | `PathLike`                                 | Source path (target)                |
| `dest`           | `PathLike`                                 | Destination path (symlink location) |
| `options`?       | \{ `force`: `boolean`; `user`: `string`; } | Symlink options                     |
| `options.force`? | `boolean`                                  | -                                   |
| `options.user`?  | `string`                                   | -                                   |

###### Returns [#returns-21]

`TemplateBuilder`

###### Example [#example-20]

```ts
template.makeSymlink('/usr/bin/python3', '/usr/bin/python')
template.makeSymlink('/usr/bin/python3', '/usr/bin/python', { user: 'root' })
template.makeSymlink('/usr/bin/python3', '/usr/bin/python', { force: true })
```

###### Implementation of [#implementation-of-20]

`TemplateBuilder`.`makeSymlink`

### npmInstall() [#npminstall]

```ts
npmInstall(packages?: string | string[], options?: object): TemplateBuilder
```

Install Node.js packages using npm.

###### Parameters [#parameters-21]

| Parameter      | Type                                   | Description                                   |
| -------------- | -------------------------------------- | --------------------------------------------- |
| `packages`?    | `string` \| `string`\[]                | Package name(s) or undefined for package.json |
| `options`?     | \{ `dev`: `boolean`; `g`: `boolean`; } | Install options                               |
| `options.dev`? | `boolean`                              | -                                             |
| `options.g`?   | `boolean`                              | -                                             |

###### Returns [#returns-22]

`TemplateBuilder`

###### Example [#example-21]

```ts
template.npmInstall('express')
template.npmInstall(['lodash', 'axios'])
template.npmInstall('tsx', { g: true })
template.npmInstall('typescript', { dev: true })
template.npmInstall()  // Installs from package.json
```

###### Implementation of [#implementation-of-21]

`TemplateBuilder`.`npmInstall`

### pipInstall() [#pipinstall]

```ts
pipInstall(packages?: string | string[], options?: object): TemplateBuilder
```

Install Python packages using pip.

###### Parameters [#parameters-22]

| Parameter    | Type                    | Description                                                                                        |
| ------------ | ----------------------- | -------------------------------------------------------------------------------------------------- |
| `packages`?  | `string` \| `string`\[] | Package name(s) or undefined for current directory                                                 |
| `options`?   | \{ `g`: `boolean`; }    | Install options                                                                                    |
| `options.g`? | `boolean`               | Install globally as root (default: true). Set to false for user-only installation with --user flag |

###### Returns [#returns-23]

`TemplateBuilder`

###### Example [#example-22]

```ts
template.pipInstall('numpy')  // Installs globally (default)
template.pipInstall(['pandas', 'scikit-learn'])
template.pipInstall('numpy', { g: false })  // Install for user only
template.pipInstall()  // Installs from current directory
```

###### Implementation of [#implementation-of-22]

`TemplateBuilder`.`pipInstall`

### remove() [#remove]

```ts
remove(path: PathLike | PathLike[], options?: object): TemplateBuilder
```

Remove files or directories.

###### Parameters [#parameters-23]

| Parameter            | Type                                                               | Description       |
| -------------------- | ------------------------------------------------------------------ | ----------------- |
| `path`               | `PathLike` \| `PathLike`\[]                                        | Path(s) to remove |
| `options`?           | \{ `force`: `boolean`; `recursive`: `boolean`; `user`: `string`; } | Remove options    |
| `options.force`?     | `boolean`                                                          | -                 |
| `options.recursive`? | `boolean`                                                          | -                 |
| `options.user`?      | `string`                                                           | -                 |

###### Returns [#returns-24]

`TemplateBuilder`

###### Example [#example-23]

```ts
template.remove('/tmp/cache', { recursive: true, force: true })
template.remove('/tmp/cache', { recursive: true, force: true, user: 'root' })
```

###### Implementation of [#implementation-of-23]

`TemplateBuilder`.`remove`

### rename() [#rename]

```ts
rename(
   src: PathLike, 
   dest: PathLike, 
   options?: object): TemplateBuilder
```

Rename or move a file or directory.

###### Parameters [#parameters-24]

| Parameter        | Type                                       | Description      |
| ---------------- | ------------------------------------------ | ---------------- |
| `src`            | `PathLike`                                 | Source path      |
| `dest`           | `PathLike`                                 | Destination path |
| `options`?       | \{ `force`: `boolean`; `user`: `string`; } | Rename options   |
| `options.force`? | `boolean`                                  | -                |
| `options.user`?  | `string`                                   | -                |

###### Returns [#returns-25]

`TemplateBuilder`

###### Example [#example-24]

```ts
template.rename('/tmp/old.txt', '/tmp/new.txt')
template.rename('/tmp/old.txt', '/tmp/new.txt', { user: 'root' })
```

###### Implementation of [#implementation-of-24]

`TemplateBuilder`.`rename`

### runCmd() [#runcmd]

###### Call Signature [#call-signature]

```ts
runCmd(command: string, options?: object): TemplateBuilder
```

Run a shell command.

###### Parameters [#parameters-25]

| Parameter       | Type                   | Description     |
| --------------- | ---------------------- | --------------- |
| `command`       | `string`               | Command string  |
| `options`?      | \{ `user`: `string`; } | Command options |
| `options.user`? | `string`               | -               |

###### Returns [#returns-26]

`TemplateBuilder`

###### Example [#example-25]

```ts
template.runCmd('apt-get update')
template.runCmd(['pip install numpy', 'pip install pandas'])
template.runCmd('apt-get install vim', { user: 'root' })
```

###### Implementation of [#implementation-of-25]

`TemplateBuilder`.`runCmd`

###### Call Signature [#call-signature-1]

```ts
runCmd(commands: string[], options?: object): TemplateBuilder
```

Run multiple shell commands.

###### Parameters [#parameters-26]

| Parameter       | Type                   | Description              |
| --------------- | ---------------------- | ------------------------ |
| `commands`      | `string`\[]            | Array of command strings |
| `options`?      | \{ `user`: `string`; } | Command options          |
| `options.user`? | `string`               | -                        |

###### Returns [#returns-27]

`TemplateBuilder`

###### Implementation of [#implementation-of-26]

`TemplateBuilder`.`runCmd`

### setEnvs() [#setenvs]

```ts
setEnvs(envs: Record<string, string>): TemplateBuilder
```

Set environment variables.
Note: Environment variables defined here are available only during template build.

###### Parameters [#parameters-27]

| Parameter | Type                          | Description           |
| --------- | ----------------------------- | --------------------- |
| `envs`    | `Record`\<`string`, `string`> | Environment variables |

###### Returns [#returns-28]

`TemplateBuilder`

###### Example [#example-26]

```ts
template.setEnvs({ NODE_ENV: 'production', PORT: '8080' })
```

###### Implementation of [#implementation-of-27]

`TemplateBuilder`.`setEnvs`

### setReadyCmd() [#setreadycmd]

```ts
setReadyCmd(readyCommand: string | ReadyCmd): TemplateFinal
```

Set or update the ready check command.

###### Parameters [#parameters-28]

| Parameter      | Type                   | Description                |
| -------------- | ---------------------- | -------------------------- |
| `readyCommand` | `string` \| `ReadyCmd` | Command to check readiness |

###### Returns [#returns-29]

`TemplateFinal`

###### Example [#example-27]

```ts
// Using a string command
template.setReadyCmd('curl http://localhost:8000/health')

// Using ReadyCmd helpers
import { waitForPort, waitForFile, waitForProcess } from 'e2b'

template.setReadyCmd(waitForPort(3000))

template.setReadyCmd(waitForFile('/tmp/ready'))

template.setReadyCmd(waitForProcess('nginx'))
```

###### Implementation of [#implementation-of-28]

`TemplateBuilder`.`setReadyCmd`

### setStartCmd() [#setstartcmd]

```ts
setStartCmd(startCommand: string, readyCommand: string | ReadyCmd): TemplateFinal
```

Set the start command and ready check.

###### Parameters [#parameters-29]

| Parameter      | Type                   | Description                |
| -------------- | ---------------------- | -------------------------- |
| `startCommand` | `string`               | Command to run on startup  |
| `readyCommand` | `string` \| `ReadyCmd` | Command to check readiness |

###### Returns [#returns-30]

`TemplateFinal`

###### Example [#example-28]

```ts
// Using a string command
template.setStartCmd(
  'node app.js',
  'curl http://localhost:8000/health'
)

// Using ReadyCmd helpers
import { waitForPort, waitForURL } from 'e2b'

template.setStartCmd(
  'python -m http.server 8000',
  waitForPort(8000)
)

template.setStartCmd(
  'npm start',
  waitForURL('http://localhost:3000/health', 200)
)
```

###### Implementation of [#implementation-of-29]

`TemplateBuilder`.`setStartCmd`

### setUser() [#setuser]

```ts
setUser(user: string): TemplateBuilder
```

Set the user for subsequent commands.

###### Parameters [#parameters-30]

| Parameter | Type     | Description |
| --------- | -------- | ----------- |
| `user`    | `string` | Username    |

###### Returns [#returns-31]

`TemplateBuilder`

###### Example [#example-29]

```ts
template.setUser('root')
```

###### Implementation of [#implementation-of-30]

`TemplateBuilder`.`setUser`

### setWorkdir() [#setworkdir]

```ts
setWorkdir(workdir: PathLike): TemplateBuilder
```

Set the working directory.

###### Parameters [#parameters-31]

| Parameter | Type       | Description            |
| --------- | ---------- | ---------------------- |
| `workdir` | `PathLike` | Working directory path |

###### Returns [#returns-32]

`TemplateBuilder`

###### Example [#example-30]

```ts
template.setWorkdir('/app')
```

###### Implementation of [#implementation-of-31]

`TemplateBuilder`.`setWorkdir`

### skipCache() [#skipcache]

```ts
skipCache(): this
```

Skip cache for all subsequent build instructions from this point.

###### Returns [#returns-33]

`this`

###### Example [#example-31]

```ts
Template().skipCache().fromPythonImage('3')
```

###### Implementation of [#implementation-of-32]

`TemplateBuilder`.`skipCache`

### ~~aliasExists()~~ [#aliasexists]

```ts
static aliasExists(alias: string, options?: ConnectionOpts): Promise<boolean>
```

Check if a template with the given alias exists.

###### Parameters [#parameters-32]

| Parameter  | Type             | Description             |
| ---------- | ---------------- | ----------------------- |
| `alias`    | `string`         | Template alias to check |
| `options`? | `ConnectionOpts` | Authentication options  |

###### Returns [#returns-34]

`Promise`\<`boolean`>

True if the alias exists, false otherwise

###### Deprecated [#deprecated]

Use `exists` instead.

###### Example [#example-32]

```ts
const exists = await Template.aliasExists('my-python-env')
if (exists) {
  console.log('Template exists!')
}
```

### assignTags() [#assigntags]

```ts
static assignTags(
   targetName: string, 
   tags: string | string[], 
options?: ConnectionOpts): Promise<TemplateTagInfo>
```

Assign tag(s) to an existing template build.

###### Parameters [#parameters-33]

| Parameter    | Type                    | Description                                                       |
| ------------ | ----------------------- | ----------------------------------------------------------------- |
| `targetName` | `string`                | Template name in 'name:tag' format (the source build to tag from) |
| `tags`       | `string` \| `string`\[] | Tag or tags to assign                                             |
| `options`?   | `ConnectionOpts`        | Authentication options                                            |

###### Returns [#returns-35]

`Promise`\<`TemplateTagInfo`>

Tag info with buildId and assigned tags

###### Example [#example-33]

```ts
// Assign a single tag
await Template.assignTags('my-template:v1.0', 'production')

// Assign multiple tags
await Template.assignTags('my-template:v1.0', ['production', 'stable'])
```

### build() [#build]

###### Call Signature [#call-signature-2]

```ts
static build(
   template: TemplateClass, 
   name: string, 
options?: Omit<BuildOptions, "alias">): Promise<BuildInfo>
```

Build and deploy a template to E2B infrastructure.

###### Parameters [#parameters-34]

| Parameter  | Type                               | Description                                  |
| ---------- | ---------------------------------- | -------------------------------------------- |
| `template` | `TemplateClass`                    | The template to build                        |
| `name`     | `string`                           | Template name in 'name' or 'name:tag' format |
| `options`? | `Omit`\<`BuildOptions`, `"alias"`> | Optional build configuration options         |

###### Returns [#returns-36]

`Promise`\<`BuildInfo`>

###### Example [#example-34]

```ts
const template = Template().fromPythonImage('3')

// Build with single tag in name
await Template.build(template, 'my-python-env:v1.0')

// Build with multiple tags
await Template.build(template, 'my-python-env', { tags: ['v1.0', 'stable'] })
```

###### Call Signature [#call-signature-3]

```ts
static build(template: TemplateClass, options: BuildOptions): Promise<BuildInfo>
```

Build and deploy a template to E2B infrastructure.

###### Parameters [#parameters-35]

| Parameter  | Type            | Description                                         |
| ---------- | --------------- | --------------------------------------------------- |
| `template` | `TemplateClass` | The template to build                               |
| `options`  | `BuildOptions`  | Build configuration options with alias (deprecated) |

###### Returns [#returns-37]

`Promise`\<`BuildInfo`>

###### Deprecated [#deprecated-1]

Use the overload with `name` parameter instead.

###### Example [#example-35]

```ts
// Deprecated:
await Template.build(template, { alias: 'my-python-env' })

// Use instead:
await Template.build(template, 'my-python-env:v1.0')
```

### buildInBackground() [#buildinbackground]

###### Call Signature [#call-signature-4]

```ts
static buildInBackground(
   template: TemplateClass, 
   name: string, 
options?: Omit<BuildOptions, "alias">): Promise<BuildInfo>
```

Build and deploy a template to E2B infrastructure without waiting for completion.

###### Parameters [#parameters-36]

| Parameter  | Type                               | Description                                  |
| ---------- | ---------------------------------- | -------------------------------------------- |
| `template` | `TemplateClass`                    | The template to build                        |
| `name`     | `string`                           | Template name in 'name' or 'name:tag' format |
| `options`? | `Omit`\<`BuildOptions`, `"alias"`> | Optional build configuration options         |

###### Returns [#returns-38]

`Promise`\<`BuildInfo`>

###### Example [#example-36]

```ts
const template = Template().fromPythonImage('3')

// Build with single tag in name
const data = await Template.buildInBackground(template, 'my-python-env:v1.0')

// Build with multiple tags
const data = await Template.buildInBackground(template, 'my-python-env', { tags: ['v1.0', 'stable'] })
```

###### Call Signature [#call-signature-5]

```ts
static buildInBackground(template: TemplateClass, options: BuildOptions): Promise<BuildInfo>
```

Build and deploy a template to E2B infrastructure without waiting for completion.

###### Parameters [#parameters-37]

| Parameter  | Type            | Description                                         |
| ---------- | --------------- | --------------------------------------------------- |
| `template` | `TemplateClass` | The template to build                               |
| `options`  | `BuildOptions`  | Build configuration options with alias (deprecated) |

###### Returns [#returns-39]

`Promise`\<`BuildInfo`>

###### Deprecated [#deprecated-2]

Use the overload with `name` parameter instead.

###### Example [#example-37]

```ts
// Deprecated:
await Template.buildInBackground(template, { alias: 'my-python-env' })

// Use instead:
await Template.buildInBackground(template, 'my-python-env:v1.0')
```

### exists() [#exists]

```ts
static exists(name: string, options?: ConnectionOpts): Promise<boolean>
```

Check if a template with the given name exists.

###### Parameters [#parameters-38]

| Parameter  | Type             | Description            |
| ---------- | ---------------- | ---------------------- |
| `name`     | `string`         | Template name to check |
| `options`? | `ConnectionOpts` | Authentication options |

###### Returns [#returns-40]

`Promise`\<`boolean`>

True if the name exists, false otherwise

###### Example [#example-38]

```ts
const exists = await Template.exists('my-python-env')
if (exists) {
  console.log('Template exists!')
}
```

### getBuildStatus() [#getbuildstatus]

```ts
static getBuildStatus(data: Pick<BuildInfo, "templateId" | "buildId">, options?: GetBuildStatusOptions): Promise<TemplateBuildStatusResponse>
```

Get the status of a build.

###### Parameters [#parameters-39]

| Parameter  | Type                                                | Description            |
| ---------- | --------------------------------------------------- | ---------------------- |
| `data`     | `Pick`\<`BuildInfo`, `"templateId"` \| `"buildId"`> | Build identifiers      |
| `options`? | `GetBuildStatusOptions`                             | Authentication options |

###### Returns [#returns-41]

`Promise`\<`TemplateBuildStatusResponse`>

###### Example [#example-39]

```ts
const status = await Template.getBuildStatus(data, { logsOffset: 0 })
```

### getTags() [#gettags]

```ts
static getTags(templateId: string, options?: ConnectionOpts): Promise<TemplateTag[]>
```

Get all tags for a template.

###### Parameters [#parameters-40]

| Parameter    | Type             | Description            |
| ------------ | ---------------- | ---------------------- |
| `templateId` | `string`         | Template ID or name    |
| `options`?   | `ConnectionOpts` | Authentication options |

###### Returns [#returns-42]

`Promise`\<`TemplateTag`\[]>

Array of tag details including tag name, buildId, and creation date

###### Example [#example-40]

```ts
const tags = await Template.getTags('my-template')
for (const tag of tags) {
  console.log(`Tag: ${tag.tag}, Build: ${tag.buildId}, Created: ${tag.createdAt}`)
}
```

### removeTags() [#removetags]

```ts
static removeTags(
   name: string, 
   tags: string | string[], 
options?: ConnectionOpts): Promise<void>
```

Remove tag(s) from a template.

###### Parameters [#parameters-41]

| Parameter  | Type                    | Description            |
| ---------- | ----------------------- | ---------------------- |
| `name`     | `string`                | Template name          |
| `tags`     | `string` \| `string`\[] | Tag or tags to remove  |
| `options`? | `ConnectionOpts`        | Authentication options |

###### Returns [#returns-43]

`Promise`\<`void`>

###### Example [#example-41]

```ts
// Remove a single tag
await Template.removeTags('my-template', 'production')

// Remove multiple tags from a template
await Template.removeTags('my-template', ['production', 'staging'])
```

### toDockerfile() [#todockerfile]

```ts
static toDockerfile(template: TemplateClass): string
```

Convert a template to Dockerfile format.
Note: Templates based on other E2B templates cannot be converted to Dockerfile.

###### Parameters [#parameters-42]

| Parameter  | Type            | Description             |
| ---------- | --------------- | ----------------------- |
| `template` | `TemplateClass` | The template to convert |

###### Returns [#returns-44]

`string`

Dockerfile string representation

###### Throws [#throws-1]

Error if the template is based on another E2B template

### toJSON() [#tojson]

```ts
static toJSON(template: TemplateClass, computeHashes: boolean): Promise<string>
```

Convert a template to JSON representation.

###### Parameters [#parameters-43]

| Parameter       | Type            | Default value | Description                                           |
| --------------- | --------------- | ------------- | ----------------------------------------------------- |
| `template`      | `TemplateClass` | `undefined`   | The template to convert                               |
| `computeHashes` | `boolean`       | `true`        | Whether to compute file hashes for cache invalidation |

###### Returns [#returns-45]

`Promise`\<`string`>

JSON string representation of the template

## Interfaces [#interfaces]

### TemplateBuilder [#templatebuilder]

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

#### Methods [#methods-1]

### addMcpServer() [#addmcpserver-1]

```ts
addMcpServer(servers: keyof McpServer | keyof McpServer[]): TemplateBuilder
```

Install MCP servers using mcp-gateway.
Note: Requires a base image with mcp-gateway pre-installed (e.g., mcp-gateway).

###### Parameters [#parameters-44]

| Parameter | Type                                  | Description        |
| --------- | ------------------------------------- | ------------------ |
| `servers` | keyof McpServer \| keyof McpServer\[] | MCP server name(s) |

###### Returns [#returns-46]

`TemplateBuilder`

###### Throws [#throws-2]

If the base template is not mcp-gateway

###### Example [#example-42]

```ts
template.addMcpServer('exa')
template.addMcpServer(['brave', 'firecrawl', 'duckduckgo'])
```

### aptInstall() [#aptinstall-1]

```ts
aptInstall(packages: string | string[], options?: object): TemplateBuilder
```

Install Debian/Ubuntu packages using apt-get.

###### Parameters [#parameters-45]

| Parameter                      | Type                                                            | Description     |
| ------------------------------ | --------------------------------------------------------------- | --------------- |
| `packages`                     | `string` \| `string`\[]                                         | Package name(s) |
| `options`?                     | \{ `fixMissing`: `boolean`; `noInstallRecommends`: `boolean`; } | -               |
| `options.fixMissing`?          | `boolean`                                                       | -               |
| `options.noInstallRecommends`? | `boolean`                                                       | -               |

###### Returns [#returns-47]

`TemplateBuilder`

###### Example [#example-43]

```ts
template.aptInstall('vim')
template.aptInstall(['git', 'curl', 'wget'])
template.aptInstall(['vim'], { noInstallRecommends: true })
template.aptInstall(['vim'], { fixMissing: true })
```

### betaDevContainerPrebuild() [#betadevcontainerprebuild-1]

```ts
betaDevContainerPrebuild(devcontainerDirectory: string): TemplateBuilder
```

Prebuild a devcontainer from the specified directory.

###### Parameters [#parameters-46]

| Parameter               | Type     | Description                        |
| ----------------------- | -------- | ---------------------------------- |
| `devcontainerDirectory` | `string` | Path to the devcontainer directory |

###### Returns [#returns-48]

`TemplateBuilder`

###### Example [#example-44]

```ts
template
 .gitClone('https://myrepo.com/project.git', '/my-devcontainer')
 .betaDevContainerPrebuild('/my-devcontainer')
```

### betaSetDevContainerStart() [#betasetdevcontainerstart-1]

```ts
betaSetDevContainerStart(devcontainerDirectory: string): TemplateFinal
```

Start a devcontainer from the specified directory.

###### Parameters [#parameters-47]

| Parameter               | Type     | Description                        |
| ----------------------- | -------- | ---------------------------------- |
| `devcontainerDirectory` | `string` | Path to the devcontainer directory |

###### Returns [#returns-49]

`TemplateFinal`

###### Example [#example-45]

```ts
template
 .gitClone('https://myrepo.com/project.git', '/my-devcontainer')
 .startDevcontainer('/my-devcontainer')

// Prebuild and start
template
 .gitClone('https://myrepo.com/project.git', '/my-devcontainer')
 .betaDevContainerPrebuild('/my-devcontainer')
 // Other instructions...
 .betaSetDevContainerStart('/my-devcontainer')
```

### bunInstall() [#buninstall-1]

```ts
bunInstall(packages?: string | string[], options?: object): TemplateBuilder
```

Install Bun packages using bun.

###### Parameters [#parameters-48]

| Parameter      | Type                                   | Description                                   |
| -------------- | -------------------------------------- | --------------------------------------------- |
| `packages`?    | `string` \| `string`\[]                | Package name(s) or undefined for package.json |
| `options`?     | \{ `dev`: `boolean`; `g`: `boolean`; } | Install options                               |
| `options.dev`? | `boolean`                              | -                                             |
| `options.g`?   | `boolean`                              | -                                             |

###### Returns [#returns-50]

`TemplateBuilder`

###### Example [#example-46]

```ts
template.bunInstall('express')
template.bunInstall(['lodash', 'axios'])
template.bunInstall('tsx', { g: true })
template.bunInstall('typescript', { dev: true })
template.bunInstall()  // Installs from package.json
```

### copy() [#copy-1]

```ts
copy(
   src: PathLike | PathLike[], 
   dest: PathLike, 
   options?: object): TemplateBuilder
```

Copy files or directories into the template.

###### Parameters [#parameters-49]

| Parameter                  | Type                                                                                          | Description      |
| -------------------------- | --------------------------------------------------------------------------------------------- | ---------------- |
| `src`                      | `PathLike` \| `PathLike`\[]                                                                   | Source path(s)   |
| `dest`                     | `PathLike`                                                                                    | Destination path |
| `options`?                 | \{ `forceUpload`: `true`; `mode`: `number`; `resolveSymlinks`: `boolean`; `user`: `string`; } | Copy options     |
| `options.forceUpload`?     | `true`                                                                                        | -                |
| `options.mode`?            | `number`                                                                                      | -                |
| `options.resolveSymlinks`? | `boolean`                                                                                     | -                |
| `options.user`?            | `string`                                                                                      | -                |

###### Returns [#returns-51]

`TemplateBuilder`

###### Example [#example-47]

```ts
template.copy('requirements.txt', '/home/user/')
template.copy(['app.ts', 'config.ts'], '/app/', { mode: 0o755 })
```

### copyItems() [#copyitems-1]

```ts
copyItems(items: CopyItem[]): TemplateBuilder
```

Copy multiple items with individual options.

###### Parameters [#parameters-50]

| Parameter | Type          | Description         |
| --------- | ------------- | ------------------- |
| `items`   | `CopyItem`\[] | Array of copy items |

###### Returns [#returns-52]

`TemplateBuilder`

###### Example [#example-48]

```ts
template.copyItems([
  { src: 'app.ts', dest: '/app/' },
  { src: 'config.ts', dest: '/app/', mode: 0o644 }
])
```

### gitClone() [#gitclone-1]

```ts
gitClone(
   url: string, 
   path?: PathLike, 
   options?: object): TemplateBuilder
```

Clone a Git repository.

###### Parameters [#parameters-51]

| Parameter         | Type                                                          | Description               |
| ----------------- | ------------------------------------------------------------- | ------------------------- |
| `url`             | `string`                                                      | Repository URL            |
| `path`?           | `PathLike`                                                    | Optional destination path |
| `options`?        | \{ `branch`: `string`; `depth`: `number`; `user`: `string`; } | Clone options             |
| `options.branch`? | `string`                                                      | -                         |
| `options.depth`?  | `number`                                                      | -                         |
| `options.user`?   | `string`                                                      | -                         |

###### Returns [#returns-53]

`TemplateBuilder`

###### Example [#example-49]

```ts
template.gitClone('https://github.com/user/repo.git', '/app/repo')
template.gitClone('https://github.com/user/repo.git', undefined, {
  branch: 'main',
  depth: 1
})
template.gitClone('https://github.com/user/repo.git', '/app/repo', {
  user: 'root'
})
```

### makeDir() [#makedir-1]

```ts
makeDir(path: PathLike | PathLike[], options?: object): TemplateBuilder
```

Create directories.

###### Parameters [#parameters-52]

| Parameter       | Type                                     | Description       |
| --------------- | ---------------------------------------- | ----------------- |
| `path`          | `PathLike` \| `PathLike`\[]              | Directory path(s) |
| `options`?      | \{ `mode`: `number`; `user`: `string`; } | Directory options |
| `options.mode`? | `number`                                 | -                 |
| `options.user`? | `string`                                 | -                 |

###### Returns [#returns-54]

`TemplateBuilder`

###### Example [#example-50]

```ts
template.makeDir('/app/data', { mode: 0o755 })
template.makeDir(['/app/logs', '/app/cache'])
template.makeDir('/app/data', { mode: 0o755, user: 'root' })
```

### makeSymlink() [#makesymlink-1]

```ts
makeSymlink(
   src: PathLike, 
   dest: PathLike, 
   options?: object): TemplateBuilder
```

Create a symbolic link.

###### Parameters [#parameters-53]

| Parameter        | Type                                       | Description                         |
| ---------------- | ------------------------------------------ | ----------------------------------- |
| `src`            | `PathLike`                                 | Source path (target)                |
| `dest`           | `PathLike`                                 | Destination path (symlink location) |
| `options`?       | \{ `force`: `boolean`; `user`: `string`; } | Symlink options                     |
| `options.force`? | `boolean`                                  | -                                   |
| `options.user`?  | `string`                                   | -                                   |

###### Returns [#returns-55]

`TemplateBuilder`

###### Example [#example-51]

```ts
template.makeSymlink('/usr/bin/python3', '/usr/bin/python')
template.makeSymlink('/usr/bin/python3', '/usr/bin/python', { user: 'root' })
template.makeSymlink('/usr/bin/python3', '/usr/bin/python', { force: true })
```

### npmInstall() [#npminstall-1]

```ts
npmInstall(packages?: string | string[], options?: object): TemplateBuilder
```

Install Node.js packages using npm.

###### Parameters [#parameters-54]

| Parameter      | Type                                   | Description                                   |
| -------------- | -------------------------------------- | --------------------------------------------- |
| `packages`?    | `string` \| `string`\[]                | Package name(s) or undefined for package.json |
| `options`?     | \{ `dev`: `boolean`; `g`: `boolean`; } | Install options                               |
| `options.dev`? | `boolean`                              | -                                             |
| `options.g`?   | `boolean`                              | -                                             |

###### Returns [#returns-56]

`TemplateBuilder`

###### Example [#example-52]

```ts
template.npmInstall('express')
template.npmInstall(['lodash', 'axios'])
template.npmInstall('tsx', { g: true })
template.npmInstall('typescript', { dev: true })
template.npmInstall()  // Installs from package.json
```

### pipInstall() [#pipinstall-1]

```ts
pipInstall(packages?: string | string[], options?: object): TemplateBuilder
```

Install Python packages using pip.

###### Parameters [#parameters-55]

| Parameter    | Type                    | Description                                                                                        |
| ------------ | ----------------------- | -------------------------------------------------------------------------------------------------- |
| `packages`?  | `string` \| `string`\[] | Package name(s) or undefined for current directory                                                 |
| `options`?   | \{ `g`: `boolean`; }    | Install options                                                                                    |
| `options.g`? | `boolean`               | Install globally as root (default: true). Set to false for user-only installation with --user flag |

###### Returns [#returns-57]

`TemplateBuilder`

###### Example [#example-53]

```ts
template.pipInstall('numpy')  // Installs globally (default)
template.pipInstall(['pandas', 'scikit-learn'])
template.pipInstall('numpy', { g: false })  // Install for user only
template.pipInstall()  // Installs from current directory
```

### remove() [#remove-1]

```ts
remove(path: PathLike | PathLike[], options?: object): TemplateBuilder
```

Remove files or directories.

###### Parameters [#parameters-56]

| Parameter            | Type                                                               | Description       |
| -------------------- | ------------------------------------------------------------------ | ----------------- |
| `path`               | `PathLike` \| `PathLike`\[]                                        | Path(s) to remove |
| `options`?           | \{ `force`: `boolean`; `recursive`: `boolean`; `user`: `string`; } | Remove options    |
| `options.force`?     | `boolean`                                                          | -                 |
| `options.recursive`? | `boolean`                                                          | -                 |
| `options.user`?      | `string`                                                           | -                 |

###### Returns [#returns-58]

`TemplateBuilder`

###### Example [#example-54]

```ts
template.remove('/tmp/cache', { recursive: true, force: true })
template.remove('/tmp/cache', { recursive: true, force: true, user: 'root' })
```

### rename() [#rename-1]

```ts
rename(
   src: PathLike, 
   dest: PathLike, 
   options?: object): TemplateBuilder
```

Rename or move a file or directory.

###### Parameters [#parameters-57]

| Parameter        | Type                                       | Description      |
| ---------------- | ------------------------------------------ | ---------------- |
| `src`            | `PathLike`                                 | Source path      |
| `dest`           | `PathLike`                                 | Destination path |
| `options`?       | \{ `force`: `boolean`; `user`: `string`; } | Rename options   |
| `options.force`? | `boolean`                                  | -                |
| `options.user`?  | `string`                                   | -                |

###### Returns [#returns-59]

`TemplateBuilder`

###### Example [#example-55]

```ts
template.rename('/tmp/old.txt', '/tmp/new.txt')
template.rename('/tmp/old.txt', '/tmp/new.txt', { user: 'root' })
```

### runCmd() [#runcmd-1]

###### Call Signature [#call-signature-6]

```ts
runCmd(command: string, options?: object): TemplateBuilder
```

Run a shell command.

###### Parameters [#parameters-58]

| Parameter       | Type                   | Description     |
| --------------- | ---------------------- | --------------- |
| `command`       | `string`               | Command string  |
| `options`?      | \{ `user`: `string`; } | Command options |
| `options.user`? | `string`               | -               |

###### Returns [#returns-60]

`TemplateBuilder`

###### Example [#example-56]

```ts
template.runCmd('apt-get update')
template.runCmd(['pip install numpy', 'pip install pandas'])
template.runCmd('apt-get install vim', { user: 'root' })
```

###### Call Signature [#call-signature-7]

```ts
runCmd(commands: string[], options?: object): TemplateBuilder
```

Run multiple shell commands.

###### Parameters [#parameters-59]

| Parameter       | Type                   | Description              |
| --------------- | ---------------------- | ------------------------ |
| `commands`      | `string`\[]            | Array of command strings |
| `options`?      | \{ `user`: `string`; } | Command options          |
| `options.user`? | `string`               | -                        |

###### Returns [#returns-61]

`TemplateBuilder`

###### Call Signature [#call-signature-8]

```ts
runCmd(commandOrCommands: string | string[], options?: object): TemplateBuilder
```

Run command(s).

###### Parameters [#parameters-60]

| Parameter           | Type                    | Description         |
| ------------------- | ----------------------- | ------------------- |
| `commandOrCommands` | `string` \| `string`\[] | Command or commands |
| `options`?          | \{ `user`: `string`; }  | Command options     |
| `options.user`?     | `string`                | -                   |

###### Returns [#returns-62]

`TemplateBuilder`

### setEnvs() [#setenvs-1]

```ts
setEnvs(envs: Record<string, string>): TemplateBuilder
```

Set environment variables.
Note: Environment variables defined here are available only during template build.

###### Parameters [#parameters-61]

| Parameter | Type                          | Description           |
| --------- | ----------------------------- | --------------------- |
| `envs`    | `Record`\<`string`, `string`> | Environment variables |

###### Returns [#returns-63]

`TemplateBuilder`

###### Example [#example-57]

```ts
template.setEnvs({ NODE_ENV: 'production', PORT: '8080' })
```

### setReadyCmd() [#setreadycmd-1]

```ts
setReadyCmd(readyCommand: string | ReadyCmd): TemplateFinal
```

Set or update the ready check command.

###### Parameters [#parameters-62]

| Parameter      | Type                   | Description                |
| -------------- | ---------------------- | -------------------------- |
| `readyCommand` | `string` \| `ReadyCmd` | Command to check readiness |

###### Returns [#returns-64]

`TemplateFinal`

###### Example [#example-58]

```ts
// Using a string command
template.setReadyCmd('curl http://localhost:8000/health')

// Using ReadyCmd helpers
import { waitForPort, waitForFile, waitForProcess } from 'e2b'

template.setReadyCmd(waitForPort(3000))

template.setReadyCmd(waitForFile('/tmp/ready'))

template.setReadyCmd(waitForProcess('nginx'))
```

### setStartCmd() [#setstartcmd-1]

```ts
setStartCmd(startCommand: string, readyCommand: string | ReadyCmd): TemplateFinal
```

Set the start command and ready check.

###### Parameters [#parameters-63]

| Parameter      | Type                   | Description                |
| -------------- | ---------------------- | -------------------------- |
| `startCommand` | `string`               | Command to run on startup  |
| `readyCommand` | `string` \| `ReadyCmd` | Command to check readiness |

###### Returns [#returns-65]

`TemplateFinal`

###### Example [#example-59]

```ts
// Using a string command
template.setStartCmd(
  'node app.js',
  'curl http://localhost:8000/health'
)

// Using ReadyCmd helpers
import { waitForPort, waitForURL } from 'e2b'

template.setStartCmd(
  'python -m http.server 8000',
  waitForPort(8000)
)

template.setStartCmd(
  'npm start',
  waitForURL('http://localhost:3000/health', 200)
)
```

### setUser() [#setuser-1]

```ts
setUser(user: string): TemplateBuilder
```

Set the user for subsequent commands.

###### Parameters [#parameters-64]

| Parameter | Type     | Description |
| --------- | -------- | ----------- |
| `user`    | `string` | Username    |

###### Returns [#returns-66]

`TemplateBuilder`

###### Example [#example-60]

```ts
template.setUser('root')
```

### setWorkdir() [#setworkdir-1]

```ts
setWorkdir(workdir: PathLike): TemplateBuilder
```

Set the working directory.

###### Parameters [#parameters-65]

| Parameter | Type       | Description            |
| --------- | ---------- | ---------------------- |
| `workdir` | `PathLike` | Working directory path |

###### Returns [#returns-67]

`TemplateBuilder`

###### Example [#example-61]

```ts
template.setWorkdir('/app')
```

### skipCache() [#skipcache-1]

```ts
skipCache(): this
```

Skip cache for all subsequent build instructions from this point.

###### Returns [#returns-68]

`this`

###### Example [#example-62]

```ts
template.skipCache().runCmd('apt-get update')
```

## Type Aliases [#type-aliases]

### BuildInfo [#buildinfo]

```ts
type BuildInfo = object;
```

Information about a built template.

#### Type declaration [#type-declaration]

| Name                               | Type        | Description                                                                                 |
| ---------------------------------- | ----------- | ------------------------------------------------------------------------------------------- |
| <a id="alias" /> `alias`           | `string`    | First alias from the build (for backward compatibility). **Deprecated** Use `name` instead. |
| <a id="buildid" /> `buildId`       | `string`    | Build identifier.                                                                           |
| <a id="name" /> `name`             | `string`    | Name of the template.                                                                       |
| <a id="tags" /> `tags`             | `string`\[] | Tags assigned to this build.                                                                |
| <a id="templateid" /> `templateId` | `string`    | Template identifier.                                                                        |

***

### BuildOptions [#buildoptions]

```ts
type BuildOptions = ConnectionOpts & BasicBuildOptions;
```

Options for building a template with authentication.

***

### BuildStatusReason [#buildstatusreason]

```ts
type BuildStatusReason = object;
```

Reason for the current build status (typically for errors).

#### Type declaration [#type-declaration-1]

| Name                               | Type          | Description                               |
| ---------------------------------- | ------------- | ----------------------------------------- |
| <a id="logentries" /> `logEntries` | `LogEntry`\[] | Log entries related to the status reason. |
| <a id="message" /> `message`       | `string`      | Message with the status reason.           |
| <a id="step" /> `step`?            | `string`      | Step that failed.                         |

***

### CopyItem [#copyitem]

```ts
type CopyItem = object;
```

Configuration for a single file/directory copy operation.

#### Type declaration [#type-declaration-2]

| Name                                          | Type                        |
| --------------------------------------------- | --------------------------- |
| <a id="dest" /> `dest`                        | `PathLike`                  |
| <a id="forceupload" /> `forceUpload`?         | `true`                      |
| <a id="mode" /> `mode`?                       | `number`                    |
| <a id="resolvesymlinks" /> `resolveSymlinks`? | `boolean`                   |
| <a id="src" /> `src`                          | `PathLike` \| `PathLike`\[] |
| <a id="user" /> `user`?                       | `string`                    |

***

### GetBuildStatusOptions [#getbuildstatusoptions]

```ts
type GetBuildStatusOptions = ConnectionOpts & object;
```

Options for getting build status.

#### Type declaration [#type-declaration-3]

| Name          | Type     |
| ------------- | -------- |
| `logsOffset`? | `number` |

***

### McpServerName [#mcpservername]

```ts
type McpServerName = keyof McpServer;
```

MCP server names that can be installed.

***

### TemplateBuildStatus [#templatebuildstatus]

```ts
type TemplateBuildStatus = "building" | "waiting" | "ready" | "error";
```

Status of a template build.

***

### TemplateBuildStatusResponse [#templatebuildstatusresponse]

```ts
type TemplateBuildStatusResponse = object;
```

Response from getting build status.

#### Type declaration [#type-declaration-4]

| Name                                 | Type                  | Description                                                        |
| ------------------------------------ | --------------------- | ------------------------------------------------------------------ |
| <a id="buildid-1" /> `buildID`       | `string`              | Build identifier.                                                  |
| <a id="logentries-1" /> `logEntries` | `LogEntry`\[]         | Build log entries.                                                 |
| <a id="logs" /> `logs`               | `string`\[]           | Build logs (raw strings). **Deprecated** Use `logEntries` instead. |
| <a id="reason" /> `reason`?          | `BuildStatusReason`   | Reason for the current status (typically for errors).              |
| <a id="status" /> `status`           | `TemplateBuildStatus` | Current status of the build.                                       |
| <a id="templateid-1" /> `templateID` | `string`              | Template identifier.                                               |

***

### TemplateClass [#templateclass]

```ts
type TemplateClass = TemplateBuilder | TemplateFinal;
```

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

***

### TemplateTag [#templatetag]

```ts
type TemplateTag = object;
```

Detailed information about a single template tag.

#### Type declaration [#type-declaration-5]

| Name                             | Type     | Description                                |
| -------------------------------- | -------- | ------------------------------------------ |
| <a id="buildid-2" /> `buildId`   | `string` | Build identifier associated with this tag. |
| <a id="createdat" /> `createdAt` | `Date`   | When this tag was assigned.                |
| <a id="tag" /> `tag`             | `string` | Name of the tag.                           |

***

### TemplateTagInfo [#templatetaginfo]

```ts
type TemplateTagInfo = object;
```

Information about assigned template tags.

#### Type declaration [#type-declaration-6]

| Name                           | Type        | Description                                |
| ------------------------------ | ----------- | ------------------------------------------ |
| <a id="buildid-3" /> `buildId` | `string`    | Build identifier associated with this tag. |
| <a id="tags-1" /> `tags`       | `string`\[] | Assigned tags of the template.             |

## Functions [#functions]

### Template() [#template]

```ts
function Template(options?: TemplateOptions): TemplateFromImage
```

Create a new E2B template builder instance.

#### Parameters [#parameters-66]

| Parameter  | Type              | Description                                     |
| ---------- | ----------------- | ----------------------------------------------- |
| `options`? | `TemplateOptions` | Optional configuration for the template builder |

#### Returns [#returns-69]

`TemplateFromImage`

A new template builder instance

#### Example [#example-63]

```ts
import { Template } from 'e2b'

const template = Template()
  .fromPythonImage('3')
  .copy('requirements.txt', '/app/')
  .pipInstall()

await Template.build(template, 'my-python-app:v1.0')
```
