> ## Documentation Index
> Fetch the complete documentation index at: https://docs.e2b.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Template sync

### check\_alias\_exists

```python theme={"theme":"css-variables"}
def check_alias_exists(client: AuthenticatedClient, alias: str) -> bool
```

Check if a template with the given alias exists.

**Arguments**:

* `client` - Authenticated API client
* `alias` - Template alias to check

**Returns**:

True if the alias exists, False otherwise

### assign\_tags

```python theme={"theme":"css-variables"}
def assign_tags(client: AuthenticatedClient, target_name: str,
                tags: List[str]) -> TemplateTagInfo
```

Assign tag(s) to an existing template build.

**Arguments**:

* `client` - Authenticated API client
* `target_name` - Template name in 'name:tag' format (the source build to tag from)
* `tags` - Tags to assign

**Returns**:

TemplateTagInfo with build\_id and assigned tags

### remove\_tags

```python theme={"theme":"css-variables"}
def remove_tags(client: AuthenticatedClient, name: str,
                tags: List[str]) -> None
```

Remove tag(s) from a template.

**Arguments**:

* `client` - Authenticated API client
* `name` - Template name
* `tags` - List of tags to remove

### get\_template\_tags

```python theme={"theme":"css-variables"}
def get_template_tags(client: AuthenticatedClient,
                      template_id_or_name: str) -> List[TemplateTag]
```

Get all tags for a template.

**Arguments**:

* `client` - Authenticated API client
* `template_id_or_name` - Template ID or name (a name may be namespaced)

## Template

```python theme={"theme":"css-variables"}
class Template(TemplateBase)
```

Synchronous template builder for E2B sandboxes.

### build

```python theme={"theme":"css-variables"}
@classmethod
def build(cls,
          template: TemplateClass,
          name: Optional[str] = None,
          *,
          alias: Optional[str] = None,
          tags: Optional[List[str]] = None,
          cpu_count: Optional[int] = None,
          memory_mb: Optional[int] = None,
          min_free_disk_mb: Optional[int] = None,
          skip_cache: bool = False,
          on_build_logs: Optional[Callable[[LogEntry], None]] = None,
          **opts: Unpack[ApiParams]) -> BuildInfo
```

Build and deploy a template to E2B infrastructure.

**Arguments**:

* `template`: The template to build
* `name`: Template name in 'name' or 'name:tag' format
* `alias`: (Deprecated) Alias name for the template. Use name instead.
* `tags`: Optional additional tags to assign to the template
* `cpu_count`: Number of CPUs allocated to the sandbox.
* `memory_mb`: Amount of memory in MB allocated to the sandbox.
* `min_free_disk_mb`: Requested minimum free space after the build steps, in MiB. Growth is best effort and the filesystem is never shrunk. Omit to use the team default or set to 0 to request no growth.
* `skip_cache`: If True, forces a complete rebuild ignoring cache
* `on_build_logs`: Callback function to receive build logs during the build process
  Example

```python theme={"theme":"css-variables"}
from e2b import Template

template = (
    Template()
    .from_python_image('3')
    .copy('requirements.txt', '/home/user/')
    .run_cmd('pip install -r /home/user/requirements.txt')
)

# Build with single tag
Template.build(template, 'my-python-env:v1.0')

# Build with multiple tags
Template.build(template, 'my-python-env', tags=['v1.1.0', 'stable'])
```

### build\_in\_background

```python theme={"theme":"css-variables"}
@classmethod
def build_in_background(cls,
                        template: TemplateClass,
                        name: Optional[str] = None,
                        *,
                        alias: Optional[str] = None,
                        tags: Optional[List[str]] = None,
                        cpu_count: Optional[int] = None,
                        memory_mb: Optional[int] = None,
                        min_free_disk_mb: Optional[int] = None,
                        skip_cache: bool = False,
                        on_build_logs: Optional[Callable[[LogEntry],
                                                         None]] = None,
                        **opts: Unpack[ApiParams]) -> BuildInfo
```

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

**Arguments**:

* `template`: The template to build
* `name`: Template name in 'name' or 'name:tag' format
* `alias`: (Deprecated) Alias name for the template. Use name instead.
* `tags`: Optional additional tags to assign to the template
* `cpu_count`: Number of CPUs allocated to the sandbox.
* `memory_mb`: Amount of memory in MB allocated to the sandbox.
* `min_free_disk_mb`: Requested minimum free space after the build steps, in MiB. Growth is best effort and the filesystem is never shrunk. Omit to use the team default or set to 0 to request no growth.
* `skip_cache`: If True, forces a complete rebuild ignoring cache

**Returns**:

BuildInfo containing the template ID and build ID
Example

```python theme={"theme":"css-variables"}
from e2b import Template

template = (
    Template()
    .from_python_image('3')
    .run_cmd('echo "test"')
    .set_start_cmd('echo "Hello"', 'sleep 1')
)

# Build with single tag
build_info = Template.build_in_background(template, 'my-python-env:v1.0')

# Build with multiple tags
build_info = Template.build_in_background(template, 'my-python-env', tags=['v1.1.0', 'stable'])
```

### get\_build\_status

```python theme={"theme":"css-variables"}
@classmethod
def get_build_status(cls,
                     build_info: BuildInfo,
                     logs_offset: Optional[int] = None,
                     **opts: Unpack[ApiParams])
```

Get the status of a build.

**Arguments**:

* `build_info`: Build identifiers returned from build\_in\_background
* `logs_offset`: Offset for fetching logs; when omitted, the API default applies

**Returns**:

TemplateBuild containing the build status and logs
Example

```python theme={"theme":"css-variables"}
from e2b import Template

build_info = Template.build_in_background(template, alias='my-template')
status = Template.get_build_status(build_info)
```

### exists

```python theme={"theme":"css-variables"}
@classmethod
def exists(cls, name: str, **opts: Unpack[ApiParams]) -> bool
```

Check if a template with the given name exists.

**Arguments**:

* `name`: Template name to check

**Returns**:

True if the name exists, False otherwise
Example

```python theme={"theme":"css-variables"}
from e2b import Template

exists = Template.exists('my-python-env')
if exists:
    print('Template exists!')
```

### alias\_exists

```python theme={"theme":"css-variables"}
@classmethod
def alias_exists(cls, alias: str, **opts: Unpack[ApiParams]) -> bool
```

Check if a template with the given alias exists.

Deprecated Use `exists` instead.

**Arguments**:

* `alias`: Template alias to check

**Returns**:

True if the alias exists, False otherwise
Example

```python theme={"theme":"css-variables"}
from e2b import Template

exists = Template.alias_exists('my-python-env')
if exists:
    print('Template exists!')
```

### assign\_tags

```python theme={"theme":"css-variables"}
@classmethod
def assign_tags(cls, target_name: str, tags: Union[str, List[str]],
                **opts: Unpack[ApiParams]) -> TemplateTagInfo
```

Assign tag(s) to an existing template build.

**Arguments**:

* `target_name`: Template name in 'name:tag' format (the source build to tag from)
* `tags`: Tag or tags to assign

**Returns**:

TemplateTagInfo with build\_id and assigned tags
Example

```python theme={"theme":"css-variables"}
from e2b import Template

# Assign a single tag
result = Template.assign_tags('my-template:v1.0', 'production')

# Assign multiple tags
result = Template.assign_tags('my-template:v1.0', ['production', 'stable'])
```

### remove\_tags

```python theme={"theme":"css-variables"}
@classmethod
def remove_tags(cls, name: str, tags: Union[str, List[str]],
                **opts: Unpack[ApiParams]) -> None
```

Remove tag(s) from a template.

**Arguments**:

* `name`: Template name
* `tags`: Tag or tags to remove
  Example

```python theme={"theme":"css-variables"}
from e2b import Template

# Remove a single tag
Template.remove_tags('my-template', 'production')

# Remove multiple tags
Template.remove_tags('my-template', ['production', 'stable'])
```

### get\_tags

```python theme={"theme":"css-variables"}
@classmethod
def get_tags(cls, template_id: str,
             **opts: Unpack[ApiParams]) -> List[TemplateTag]
```

Get all tags for a template.

**Arguments**:

* `template_id`: Template ID or name

**Returns**:

List of TemplateTag with tag name, build\_id, and created\_at
Example

```python theme={"theme":"css-variables"}
from e2b import Template

tags = Template.get_tags('my-template')
for tag in tags:
    print(f"Tag: {tag.tag}, Build: {tag.build_id}, Created: {tag.created_at}")
```

### \_\_init\_\_

```python theme={"theme":"css-variables"}
def __init__(file_context_path: Optional[Union[str, Path]] = None,
             file_ignore_patterns: Optional[List[str]] = None)
```

Create a new template builder instance.

**Arguments**:

* `file_context_path`: Base path for resolving relative file paths in copy operations
* `file_ignore_patterns`: Patterns in `.dockerignore` syntax for files to exclude when copying. They are applied after the `.dockerignore` file in the context directory, so they take precedence over it. An invalid pattern (such as an unterminated `[`) raises a :class:`TemplateException`. Brace expansion (`{a,b}`) is not supported, as in Docker

### skip\_cache

```python theme={"theme":"css-variables"}
def skip_cache() -> "TemplateBase"
```

Skip cache for all subsequent build instructions from this point.

**Returns**:

`TemplateBase` class
Example

```python theme={"theme":"css-variables"}
template.skip_cache().from_python_image('3.11')
```

### from\_debian\_image

```python theme={"theme":"css-variables"}
def from_debian_image(variant: str = "stable") -> TemplateBuilder
```

Start template from a Debian base image.

**Arguments**:

* `variant`: Debian image variant

**Returns**:

`TemplateBuilder` class
Example

```python theme={"theme":"css-variables"}
Template().from_debian_image('bookworm')
```

### from\_ubuntu\_image

```python theme={"theme":"css-variables"}
def from_ubuntu_image(variant: str = "latest") -> TemplateBuilder
```

Start template from an Ubuntu base image.

**Arguments**:

* `variant`: Ubuntu image variant (default: 'latest')

**Returns**:

`TemplateBuilder` class
Example

```python theme={"theme":"css-variables"}
Template().from_ubuntu_image('24.04')
```

### from\_fedora\_image

```python theme={"theme":"css-variables"}
def from_fedora_image(variant: str = "44") -> TemplateBuilder
```

Start template from a Fedora base image.

**Arguments**:

* `variant`: Fedora image variant (default: '44')

**Returns**:

`TemplateBuilder` class
Example

```python theme={"theme":"css-variables"}
Template().from_fedora_image('44')
```

### from\_alpine\_image

```python theme={"theme":"css-variables"}
def from_alpine_image(variant: str = "3.24") -> TemplateBuilder
```

Start template from an Alpine base image.

**Arguments**:

* `variant`: Alpine image variant (default: '3.24')

**Returns**:

`TemplateBuilder` class
Example

```python theme={"theme":"css-variables"}
Template().from_alpine_image('3.24')
```

### from\_arch\_image

```python theme={"theme":"css-variables"}
def from_arch_image(variant: str = "latest") -> TemplateBuilder
```

Start template from an Arch Linux base image.

Defaults to `latest`: Arch is a rolling release and template
provisioning runs `pacman -Syu`, so pinning a tag would not change
the built result.

**Arguments**:

* `variant`: Arch Linux image variant (default: 'latest')

**Returns**:

`TemplateBuilder` class
Example

```python theme={"theme":"css-variables"}
Template().from_arch_image('base-devel')
```

### from\_python\_image

```python theme={"theme":"css-variables"}
def from_python_image(version: str = "3") -> TemplateBuilder
```

Start template from a Python base image.

**Arguments**:

* `version`: Python version (default: '3')

**Returns**:

`TemplateBuilder` class
Example

```python theme={"theme":"css-variables"}
Template().from_python_image('3')
```

### from\_node\_image

```python theme={"theme":"css-variables"}
def from_node_image(variant: str = "lts") -> TemplateBuilder
```

Start template from a Node.js base image.

**Arguments**:

* `variant`: Node.js image variant (default: 'lts')

**Returns**:

`TemplateBuilder` class
Example

```python theme={"theme":"css-variables"}
Template().from_node_image('24')
```

### from\_bun\_image

```python theme={"theme":"css-variables"}
def from_bun_image(variant: str = "latest") -> TemplateBuilder
```

Start template from a Bun base image.

**Arguments**:

* `variant`: Bun image variant (default: 'latest')

**Returns**:

`TemplateBuilder` class

### from\_base\_image

```python theme={"theme":"css-variables"}
def from_base_image() -> TemplateBuilder
```

Start template from the E2B base image (e2bdev/base:latest).

**Returns**:

`TemplateBuilder` class
Example

```python theme={"theme":"css-variables"}
Template().from_base_image()
```

### from\_image

```python theme={"theme":"css-variables"}
def from_image(image: str,
               username: Optional[str] = None,
               password: Optional[str] = None) -> TemplateBuilder
```

Start template from a Docker image.

**Arguments**:

* `image`: Docker image name (e.g., 'ubuntu:24.04')
* `username`: Username for private registry authentication
* `password`: Password for private registry authentication

**Returns**:

`TemplateBuilder` class
Example

```python theme={"theme":"css-variables"}
Template().from_image('python:3')

# With credentials (optional)
Template().from_image('myregistry.com/myimage:latest', username='user', password='pass')
```

### from\_template

```python theme={"theme":"css-variables"}
def from_template(template: str) -> TemplateBuilder
```

Start template from an existing E2B template.

**Arguments**:

* `template`: E2B template ID or alias

**Returns**:

`TemplateBuilder` class
Example

```python theme={"theme":"css-variables"}
Template().from_template('my-base-template')
```

### from\_dockerfile

```python theme={"theme":"css-variables"}
def from_dockerfile(dockerfile_content_or_path: str) -> TemplateBuilder
```

Parse a Dockerfile and convert it to Template SDK format.

**Arguments**:

* `dockerfile_content_or_path`: Either the Dockerfile content as a string, or a path to a Dockerfile file

**Returns**:

`TemplateBuilder` class
Example

```python theme={"theme":"css-variables"}
Template().from_dockerfile('Dockerfile')
Template().from_dockerfile('FROM python:3\nRUN pip install numpy')
```

### from\_aws\_registry

```python theme={"theme":"css-variables"}
def from_aws_registry(image: str, access_key_id: str, secret_access_key: str,
                      region: str) -> TemplateBuilder
```

Start template from an AWS ECR registry image.

**Arguments**:

* `image`: Docker image name from AWS ECR
* `access_key_id`: AWS access key ID
* `secret_access_key`: AWS secret access key
* `region`: AWS region

**Returns**:

`TemplateBuilder` class
Example

```python theme={"theme":"css-variables"}
Template().from_aws_registry(
    '123456789.dkr.ecr.us-west-2.amazonaws.com/myimage:latest',
    access_key_id='AKIA...',
    secret_access_key='...',
    region='us-west-2'
)
```

### from\_gcp\_registry

```python theme={"theme":"css-variables"}
def from_gcp_registry(
        image: str, service_account_json: Union[str, dict]) -> TemplateBuilder
```

Start template from a GCP Artifact Registry or Container Registry image.

**Arguments**:

* `image`: Docker image name from GCP registry
* `service_account_json`: Service account JSON string, dict, or path to JSON file

**Returns**:

`TemplateBuilder` class
Example

```python theme={"theme":"css-variables"}
Template().from_gcp_registry(
    'gcr.io/myproject/myimage:latest',
    service_account_json='path/to/service-account.json'
)
```

### to\_json

```python theme={"theme":"css-variables"}
@staticmethod
def to_json(template: "TemplateClass") -> str
```

Convert a template to JSON representation.

**Arguments**:

* `template`: The template to convert (TemplateBuilder or TemplateFinal instance)

**Returns**:

JSON string representation of the template
Example

```python theme={"theme":"css-variables"}
template = Template().from_python_image('3').copy('app.py', '/app/')
json_str = TemplateBase.to_json(template)
```

### to\_dockerfile

```python theme={"theme":"css-variables"}
@staticmethod
def to_dockerfile(template: "TemplateClass") -> str
```

Convert a template to Dockerfile format.

Note: Templates based on other E2B templates cannot be converted to Dockerfile.

**Arguments**:

* `template`: The template to convert (TemplateBuilder or TemplateFinal instance)

**Raises**:

* `ValueError`: If the template is based on another E2B template or has no base image
  Example

```python theme={"theme":"css-variables"}
template = Template().from_python_image('3').copy('app.py', '/app/')
dockerfile = TemplateBase.to_dockerfile(template)
```

**Returns**:

Dockerfile string representation
