DockerfFileFinalParserInterface
DockerfileParserInterface
run_cmd
copy
set_workdir
set_user
set_envs
set_start_cmd
parse_dockerfile
dockerfile_content_or_path: Either the Dockerfile content as a string, or a path to a Dockerfile filetemplate_builder: Interface providing template builder methods
ValueError: If the Dockerfile is invalid or unsupported
InstructionType
CopyItem
Instruction
GenericDockerRegistry
AWSRegistry
GCPRegistry
TemplateType
BuildInfo
LogEntry
LogEntryStart
LogEntryEnd
TIMER_UPDATE_INTERVAL_MS
Default minimum log level to display.DEFAULT_LEVEL
Colored labels for each log level.levels
Numeric ordering of log levels for comparison (lower = less severe).set_interval
func: Function to execute at each intervalinterval: Interval duration in seconds
default_build_logger
min_level: Minimum log level to display (default: ‘info’)
FINALIZE_STEP_NAME
Special step name for the base image phase of template building. This is the first step that sets up the base image.BASE_STEP_NAME
Stack trace depth for capturing caller information. Depth levels:- TemplateClass
- Caller method (e.g., copy(), from_image(), etc.)
STACK_TRACE_DEPTH
Default setting for whether to resolve symbolic links when copying files. When False, symlinks are copied as symlinks rather than following them.ReadyCmd
wait_for_port
ss command to check if a port is open and listening.
Arguments:
port: Port number to wait for
wait_for_url
curl to make HTTP requests and check the response status.
Arguments:
url: URL to check (e.g., ‘http://localhost:3000/health’)status_code: Expected HTTP status code (default: 200)
wait_for_process
pgrep to check if a process exists.
Arguments:
process_name: Name of the process to wait for
wait_for_file
filename: Path to the file to wait for
wait_for_timeout
sleep command to wait for a fixed duration.
Arguments:
timeout: Time to wait in milliseconds (minimum: 1000ms / 1 second)
read_dockerignore
context_path: Directory path containing the .dockerignore file
get_all_files_in_path
src: Path to the source directorycontext_path: Base directory for resolving relative pathsignore_patterns: Ignore patternsinclude_directories: Whether to include directories
calculate_files_hash
src: Source path pattern for files to copydest: Destination path where files will be copiedcontext_path: Base directory for resolving relative pathsignore_patterns: Glob patterns to ignoreresolve_symlinks: Whether to resolve symbolic links when hashingstack_trace: Optional stack trace for error reporting
ValueError: If no files match the source pattern
tar_file_stream
file_name: Glob pattern for files to includefile_context_path: Base directory for resolving file pathsignore_patterns: Ignore patternsresolve_symlinks: Whether to resolve symbolic links
strip_ansi_escape_codes
text: String with ANSI escape codes
get_caller_frame
depth: The depth of the stack trace to retrieve
get_caller_directory
depth: The depth of the stack trace
pad_octal
mode: File mode as a number (e.g., 493 for 0o755)
get_build_step_index
- BASE_STEP_NAME: Returns 0 (first step)
- FINALIZE_STEP_NAME: Returns the last index
- Numeric strings: Converted to number
step: Build step name or number as stringstack_traces_length: Total number of stack traces (used for FINALIZE_STEP_NAME)
read_gcp_service_account_json
context_path: Base directory for resolving relative file pathspath_or_content: Either a path to a JSON file or a service account object
TemplateBuilder
copy
src: Source file(s) or directory path(s) to copydest: Destination path in the templateforce_upload: Force upload even if files are cacheduser: User and optionally group (user:group) to own the filesmode: File permissions in octal format (e.g., 0o755)resolve_symlinks: Whether to resolve symlinks
TemplateBuilder class
Example
copy_items
items: List of CopyItem dictionaries with src, dest, and optional parameters
TemplateBuilder class
Example
remove
path: File(s) or directory path(s) to removeforce: Force removal without promptingrecursive: Remove directories recursivelyuser: User to run the command as
TemplateBuilder class
Example
rename
src: Source pathdest: Destination pathforce: Force rename without promptinguser: User to run the command as
TemplateBuilder class
Example
make_dir
path: Directory path(s) to createmode: Directory permissions in octal format (e.g., 0o755)user: User to run the command as
TemplateBuilder class
Example
make_symlink
src: Source path (target of the symlink)dest: Destination path (location of the symlink)user: User to run the command asforce: Force symlink without prompting
TemplateBuilder class
Example
run_cmd
command: Command string or list of commands to run (joined with &&)user: User to run the command as
TemplateBuilder class
Example
set_workdir
workdir: Path to set as the working directory
TemplateBuilder class
Example
set_user
user: Username to set
TemplateBuilder class
Example
pip_install
packages: Package name(s) to install. If None, runs ‘pip install .’ in the current directoryg: Install packages globally (default: True). If False, installs for user only
TemplateBuilder class
Example
npm_install
packages: Package name(s) to install. If None, installs from package.jsong: Install packages globallydev: Install packages as dev dependencies
TemplateBuilder class
Example
bun_install
packages: Package name(s) to install. If None, installs from package.jsong: Install packages globallydev: Install packages as dev dependencies
TemplateBuilder class
Example
apt_install
packages: Package name(s) to installno_install_recommends: Whether to install recommended packages
TemplateBuilder class
Example
add_mcp_server
servers: MCP server name(s)
TemplateBuilder class
Example
git_clone
url: Git repository URLpath: Destination path for the clonebranch: Branch to clonedepth: Clone depth for shallow clonesuser: User to run the command as
TemplateBuilder class
Example
beta_dev_container_prebuild
devcontainer_directory: Path to the devcontainer directory
TemplateBuilder class
Example
beta_set_dev_container_start
TemplateFinal, which means it must be the last method in the chain.
Arguments:
devcontainer_directory: Path to the devcontainer directory
TemplateFinal class
Example
set_envs
envs: Dictionary of environment variable names and values
TemplateBuilder class
Example
skip_cache
TemplateBuilder class
Example
set_start_cmd
start_cmd: Command to run when the sandbox startsready_cmd: Command or ReadyCmd to check if the sandbox is ready
TemplateFinal class
Example
set_ready_cmd
ready_cmd: Command or ReadyCmd to check if the sandbox is ready
TemplateFinal class
Example
TemplateFinal
TemplateBase
__init__
file_context_path: Base path for resolving relative file paths in copy operationsfile_ignore_patterns: List of glob patterns to ignore when copying files
skip_cache
TemplateBase class
Example
from_debian_image
variant: Debian image variant
TemplateBuilder class
Example
from_ubuntu_image
variant: Ubuntu image variant (default: ‘latest’)
TemplateBuilder class
Example
from_python_image
version: Python version (default: ‘3’)
TemplateBuilder class
Example
from_node_image
variant: Node.js image variant (default: ‘lts’)
TemplateBuilder class
Example
from_bun_image
variant: Bun image variant (default: ‘latest’)
TemplateBuilder class
from_base_image
TemplateBuilder class
Example
from_image
image: Docker image name (e.g., ‘ubuntu:24.04’)username: Username for private registry authenticationpassword: Password for private registry authentication
TemplateBuilder class
Example
from_template
template: E2B template ID or alias
TemplateBuilder class
Example
from_dockerfile
dockerfile_content_or_path: Either the Dockerfile content as a string, or a path to a Dockerfile file
TemplateBuilder class
Example
from_aws_registry
image: Docker image name from AWS ECRaccess_key_id: AWS access key IDsecret_access_key: AWS secret access keyregion: AWS region
TemplateBuilder class
Example
from_gcp_registry
image: Docker image name from GCP registryservice_account_json: Service account JSON string, dict, or path to JSON file
TemplateBuilder class
Example
to_json
template: The template to convert (TemplateBuilder or TemplateFinal instance)
to_dockerfile
template: The template to convert (TemplateBuilder or TemplateFinal instance)
ValueError: If the template is based on another E2B template or has no base image Example