Last Verified: 2025-01-27
Package:
hopx-ai on PyPI
Overview
TheTemplate class provides a fluent API for building custom sandbox templates. Use this to create reusable templates with specific configurations, dependencies, and ready checks.
Templates are built from base images and can include file copies, command execution, environment variables, port exposure, and ready checks.
Import
Base Image Methods
from_ubuntu_image
Start from Ubuntu base image.
version(str): Ubuntu version (e.g.,"22.04")
Template - Template instance (fluent API)
Expected Output:
from_python_image
Start from Python base image.
version(str): Python version (e.g.,"3.11")
from_node_image
Start from Node.js base image.
version(str): Node.js version (e.g.,"20")
from_image
Start from any Docker image.
image(str): Docker image nameauth(Dict, optional): Authentication credentials
Configuration Methods
copy
Copy files to the template.
src(str): Source pathdest(str): Destination pathoptions(Dict, optional): Copy options
run
Run command in template.
command(str): Command to execute
env
Set environment variable.
key(str): Environment variable namevalue(str): Environment variable value
expose
Expose port.
port(int): Port number to expose
workdir
Set working directory.
path(str): Working directory path
ready_check
Set ready check.
check(ReadyCheck): Ready check object
start_cmd
Set start command.
command(str): Start command
Building
build
Build the template.
options(Dict, optional): Build options
BuildResult - Build result with template ID and status
Example:
Examples
Example 1: Simple Python Template
Example 2: Web Server Template
Related Classes
- Ready Checks - Ready check utilities
- Sandbox - Use templates with
Sandbox.create(template=...)
See Also
- Ready Checks - Learn about ready checks
- Core Concepts: Templates - Learn about templates
Next Steps
Now that you understand template building, explore:- Ready Checks - Add readiness verification
- Building Templates - Learn template building concepts
- Template Configuration - Configure templates
- CLI Reference - Use HopX from the command line
- Custom Templates - Build custom templates

