Skip to main content
Templates let you pre-build sandbox images with specific packages, files, and environment variables. Once built, reference a template by alias in Sandbox.create({ template: 'my-alias' }).

TemplateBase

TemplateBase is a fluent class for defining template contents. Chain methods to build the definition, then pass it to Template.build().

.fromBaseImage(image?)

Set the base Docker image.
string
default:"'ubuntu:22.04'"
Docker image tag.
Returns this

.aptInstall(...packages)

Install apt packages.
string[]
required
One or more package names to install via apt-get install.
Returns this

.runCmd(cmds)

Add a build-time command (equivalent to a Dockerfile RUN).
string[]
required
Command as an array of strings (executable + arguments).
Returns this

.copy(src, dst, mode?)

Copy a local file into the image at build time.
string
required
Local path to the file.
string
required
Destination path inside the image.
number
Unix file permission bits (e.g. 0o755 for executable).
Returns this

.setEnvs(envs)

Set environment variables baked into the image.
Record<string, string>
required
Key-value pairs to set as environment variables.
Returns this

.setStartCmd(cmd)

Set a command to run when the sandbox boots.
string
required
Shell command to execute on sandbox start.
Returns this

.toJSON()

Serialize the template to a JSON-friendly object for the API. Returns Record<string, any>

Template

Template is a static class for submitting and querying template builds. All methods are async.

Template.build()

Submit a template build and wait for completion.
TemplateBase
required
The template definition to build.
string
required
Human-readable name used as template in Sandbox.create().
TemplateBuildOpts
Optional build options.

TemplateBuildOpts

number
Number of CPUs for the build worker.
number
Memory in MB for the build worker.
(log: string) => void
Callback invoked for each log line during the build.
string
API key override.
string
Domain override.
number
Per-request HTTP timeout in milliseconds.
Returns Promise<BuildInfo>

Template.buildInBackground()

Submit a template build and return immediately without waiting.
Parameters are the same as Template.build() except onBuildLogs is excluded. Returns Promise<BuildInfo>

Template.getBuildStatus()

Poll the status of a background build.
string
required
Build ID from a previous build() or buildInBackground() call. Must be alphanumeric with hyphens/underscores.
GetBuildStatusOpts
Optional: apiKey, domain, requestTimeout.
Returns Promise<TemplateBuildStatus>

Data models

BuildInfo

TemplateBuildStatus

CopyItem

GetBuildStatusOpts


Polling a background build

Using a template