Skip to main content
Templates let you pre-build sandbox images with specific packages, files, and environment variables installed. Once built, a template can be referenced by alias in Sandbox.create(template="my-template") to boot sandboxes that start from a known state.

TemplateBase

TemplateBase is a fluent builder for defining the contents of a template. Build up the definition by chaining methods, then pass it to Template.build().

Methods

.from_base_image(image)

Set the base Docker image.
str
default:"'ubuntu:22.04'"
Docker image tag to use as the base.
Returns TemplateBase (for chaining)

.apt_install(*packages)

Install apt packages.
str
required
One or more package names to install via apt-get install.
Returns TemplateBase

.run_cmd(cmds)

Add a shell command to run during the build (equivalent to a Dockerfile RUN).
list[str]
required
Command as a list of strings (the executable and its arguments).
Returns TemplateBase

.copy(src, dst, mode)

Copy a local file into the template image at build time.
str
required
Local path to the file to copy.
str
required
Destination path inside the image.
int | None
default:"None"
Unix file permission bits (e.g. 0o755 for executable).
Returns TemplateBase

.set_envs(envs)

Set environment variables baked into the template.
dict[str, str]
required
Key-value pairs to set as environment variables.
Returns TemplateBase

.set_start_cmd(cmd, ready_check)

Set a command to run when the sandbox boots.
str
required
Shell command to execute on sandbox start.
Any | None
default:"None"
Optional readiness probe configuration. Reserved for future use.
Returns TemplateBase

.to_dict()

Serialize the template definition to a dict suitable for the API. Returns dict

Template

Template is a static class for building and querying templates via the API.

Template.build()

Submit a template build and wait for it to complete.
TemplateBase
required
The template definition to build.
str
required
Human-readable name for the template. Used as the template parameter in Sandbox.create().
int
default:"1"
Number of CPUs for the build worker.
int
default:"1024"
Memory in MB for the build worker.
Callable[[str], None] | None
default:"None"
Callback invoked for each log line emitted during the build.
str | None
default:"$DECLAW_API_KEY"
API key override.
str | None
default:"$DECLAW_DOMAIN"
Domain override.
float | None
default:"None"
Per-request HTTP timeout in seconds.
Returns BuildInfo

Template.build_in_background()

Submit a template build and return immediately without waiting for it to finish.
Parameters are the same as Template.build() except on_build_logs is not accepted. Returns BuildInfo

Template.get_build_status()

Poll the status of a background build.
str
required
Build ID from a previous build() or build_in_background() call.
str | None
default:"$DECLAW_API_KEY"
API key override.
str | None
default:"$DECLAW_DOMAIN"
Domain override.
float | None
default:"None"
Per-request HTTP timeout in seconds.
Returns TemplateBuildStatus

Data models

BuildInfo

TemplateBuildStatus

CopyItem


AsyncTemplate

Use AsyncTemplate for async applications. It has the same static methods as Template but all are coroutines:
Methods: await AsyncTemplate.build(...), await AsyncTemplate.build_in_background(...), await AsyncTemplate.get_build_status(...).

Using a template in Sandbox.create()

Once a template is built successfully, reference it by alias: