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 |
|---|---|---|
fromUbuntuImage(version) | Start from Ubuntu base image | Template |
fromPythonImage(version) | Start from Python base image | Template |
fromNodeImage(version) | Start from Node.js base image | Template |
fromImage(image, auth?) | Start from custom image | Template |
aptInstall(...packages) | Install system packages | Template |
pipInstall(...packages) | Install Python packages | Template |
npmInstall(...packages) | Install Node.js packages | Template |
goInstall(...packages) | Install Go packages | Template |
cargoInstall(...packages) | Install Rust packages | Template |
copy(src, dest, options?) | Copy files/directories | Template |
runCmd(command) | Execute shell command | Template |
setEnv(key, value) | Set environment variable | Template |
setEnvs(vars) | Set multiple environment variables | Template |
setWorkdir(path) | Set working directory | Template |
setUser(user) | Set user for commands | Template |
gitClone(url, dest) | Clone git repository | Template |
setStartCmd(cmd, ready?) | Set start command | Template |
skipCache() | Skip cache for next step | Template |
getSteps() | Get all steps | Step[] |
Template.build()
Static method to build a template:template: Template instance with steps definedoptions: BuildOptions with alias, API key, and configuration
Promise<BuildResult> with templateID, buildID, status, and duration

