Template class provides a fluent API for building custom VM templates. Templates allow you to pre-configure environments with packages, files, and settings that boot in under 100ms using memory snapshots.
Overview
Templates are built using a step-based approach similar to Dockerfiles. You define a series of steps (install packages, copy files, run commands) and the SDK handles the build process, file uploads, and progress tracking.Installation
The Template builder is included in the main SDK:Quick Start
Template Class
Creating a Template
Base Images
Start your template from a base Docker image:Package Installation
Install packages using helper methods:File Operations
Copy files into the template:Commands
Execute shell commands:Environment Variables
Set environment variables:Working Directory
Set the working directory:User
Set the user for subsequent commands:Git Operations
Clone repositories:Start Command
Set a command to run when sandbox starts:Cache Control
Skip cache for a step:Building Templates
BuildOptions
Configure the build process:Building
Build the template:Progress Tracking
Monitor build progress:Complete Example
Validation
The SDK validates templates before building:- ✅ Must have a FROM step (base image)
- ✅ Must have at least one build step (RUN, COPY, APT, etc.)
- ❌ Cannot have only FROM + ENV/WORKDIR/USER
Error Handling
Best Practices
✅ Pin Package Versions
✅ Pin Package Versions
Pin versions for reproducibility:
✅ Combine Commands
✅ Combine Commands
Combine commands to reduce build time:
✅ Set Appropriate Resources
✅ Set Appropriate Resources
Configure CPU, memory, and disk for your workload:
✅ Use Progress Callbacks
✅ Use Progress Callbacks
Monitor long builds:
API Reference
Template Methods
| Method | Description | Returns |
|---|---|---|
from_ubuntu_image(version) | Start from Ubuntu base image | Template |
from_python_image(version) | Start from Python base image | Template |
from_node_image(version) | Start from Node.js base image | Template |
from_image(image, auth?) | Start from custom image | Template |
apt_install(*packages) | Install system packages | Template |
pip_install(*packages) | Install Python packages | Template |
npm_install(*packages) | Install Node.js packages | Template |
go_install(*packages) | Install Go packages | Template |
cargo_install(*packages) | Install Rust packages | Template |
copy(src, dest, options?) | Copy files/directories | Template |
run_cmd(command) | Execute shell command | Template |
set_env(key, value) | Set environment variable | Template |
set_envs(vars) | Set multiple environment variables | Template |
set_workdir(path) | Set working directory | Template |
set_user(user) | Set user for commands | Template |
git_clone(url, dest) | Clone git repository | Template |
set_start_cmd(cmd, ready?) | Set start command | Template |
skip_cache() | Skip cache for next step | Template |
get_steps() | Get all steps | List[Step] |
Template.build()
Static method to build a template:template: Template instance with steps definedoptions: BuildOptions with alias, API key, and configuration
BuildResult with template_id, build_id, status, and duration

