Skip to main content
Version: 0.3.0
Last Verified: 2025-01-27
Package: hopx-ai on PyPI

Overview

The Template 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.
Parameters:
  • version (str): Ubuntu version (e.g., "22.04")
Returns: Template - Template instance (fluent API) Expected Output:

from_python_image

Start from Python base image.
Parameters:
  • version (str): Python version (e.g., "3.11")
Expected Output:

from_node_image

Start from Node.js base image.
Parameters:
  • version (str): Node.js version (e.g., "20")
Expected Output:

from_image

Start from any Docker image.
Parameters:
  • image (str): Docker image name
  • auth (Dict, optional): Authentication credentials
Expected Output:

Configuration Methods

copy

Copy files to the template.
Parameters:
  • src (str): Source path
  • dest (str): Destination path
  • options (Dict, optional): Copy options
Expected Output:

run

Run command in template.
Parameters:
  • command (str): Command to execute
Expected Output:
Example:

env

Set environment variable.
Parameters:
  • key (str): Environment variable name
  • value (str): Environment variable value
Expected Output:

expose

Expose port.
Parameters:
  • port (int): Port number to expose
Expected Output:

workdir

Set working directory.
Parameters:
  • path (str): Working directory path
Expected Output:

ready_check

Set ready check.
Parameters:
  • check (ReadyCheck): Ready check object
Expected Output:
See Ready Checks for available ready checks.

start_cmd

Set start command.
Parameters:
  • command (str): Start command
Expected Output:

Building

build

Build the template.
Parameters:
  • options (Dict, optional): Build options
Returns: BuildResult - Build result with template ID and status Example:
Expected Output:

Examples

Example 1: Simple Python Template

Expected Output:

Example 2: Web Server Template

Expected Output:

  • Ready Checks - Ready check utilities
  • Sandbox - Use templates with Sandbox.create(template=...)

See Also

Next Steps

Now that you understand template building, explore: