Skip to main content

check_alias_exists

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

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

Remove tag(s) from a template. Arguments:
  • client - Authenticated API client
  • name - Template name
  • tags - List of tags to remove

get_template_tags

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

Synchronous template builder for E2B sandboxes.

build

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

build_in_background

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

get_build_status

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

exists

Check if a template with the given name exists. Arguments:
  • name: Template name to check
Returns: True if the name exists, False otherwise Example

alias_exists

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

assign_tags

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

remove_tags

Remove tag(s) from a template. Arguments:
  • name: Template name
  • tags: Tag or tags to remove Example

get_tags

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

__init__

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

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

from_debian_image

Start template from a Debian base image. Arguments:
  • variant: Debian image variant
Returns: TemplateBuilder class Example

from_ubuntu_image

Start template from an Ubuntu base image. Arguments:
  • variant: Ubuntu image variant (default: ‘latest’)
Returns: TemplateBuilder class Example

from_fedora_image

Start template from a Fedora base image. Arguments:
  • variant: Fedora image variant (default: ‘44’)
Returns: TemplateBuilder class Example

from_alpine_image

Start template from an Alpine base image. Arguments:
  • variant: Alpine image variant (default: ‘3.24’)
Returns: TemplateBuilder class Example

from_arch_image

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

from_python_image

Start template from a Python base image. Arguments:
  • version: Python version (default: ‘3’)
Returns: TemplateBuilder class Example

from_node_image

Start template from a Node.js base image. Arguments:
  • variant: Node.js image variant (default: ‘lts’)
Returns: TemplateBuilder class Example

from_bun_image

Start template from a Bun base image. Arguments:
  • variant: Bun image variant (default: ‘latest’)
Returns: TemplateBuilder class

from_base_image

Start template from the E2B base image (e2bdev/base:latest). Returns: TemplateBuilder class Example

from_image

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

from_template

Start template from an existing E2B template. Arguments:
  • template: E2B template ID or alias
Returns: TemplateBuilder class Example

from_dockerfile

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

from_aws_registry

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

from_gcp_registry

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

to_json

Convert a template to JSON representation. Arguments:
  • template: The template to convert (TemplateBuilder or TemplateFinal instance)
Returns: JSON string representation of the template Example

to_dockerfile

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
Returns: Dockerfile string representation