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.
TemplateBase (for chaining)
.apt_install(*packages)
Install apt packages.
str
required
One or more package names to install via
apt-get install.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).
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).TemplateBase
.set_envs(envs)
Set environment variables for commands run in sandboxes created from the
template. A sandbox’s own envs win on conflict.
dict[str, str]
required
Key-value pairs to set as environment variables.
TemplateBase
.set_start_cmd(cmd, ready_check)
Set a command to run when the sandbox boots.
The start command is recorded with the template but is not yet run when a
sandbox boots. Start long-running processes with
sandbox.commands.run(..., background=True) after creating the sandbox.str
required
Shell command to execute on sandbox start.
Any | None
default:"None"
Optional readiness probe configuration. Reserved for future use.
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()
Build a template and wait for the build to finish. Builds usually take several
minutes; while waiting, each new line of build output is passed to
on_build_logs.
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:"512"
Memory in MB for the build worker.
int
default:"4096"
Disk size in MB for the template: 512, 2048, 4096, 8192 or 16384. Other sizes round up to the next one.
Callable[[str], None] | None
default:"None"
Called with each new line of build output while the build runs. The server keeps
the newest 2,000 lines; if more arrive between two checks, a
... [earlier build output truncated] line marks the gap.float
default:"3600"
Seconds to wait for the build to finish. If it is still running,
TimeoutError
is raised; the build keeps running, and get_build_status() follows it.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.
BuildInfo with status completed.
Raises
BuildError— the build failed. The message quotes the end of the build output;.build_idand.logshold the rest.TimeoutError— the build was still running afterbuild_timeoutseconds.- The error from a status check that keeps failing: temporary failures (5xx, 429,
no response) are retried for up to two minutes, other errors (e.g.
NotFoundError) end the wait at once. The build itself keeps running. InvalidArgumentError— the template usescopy(), which is not supported yet.
Template.build_in_background()
Submit a template build and return immediately without waiting for it to finish.
Template.build() except on_build_logs and
build_timeout, which only apply while waiting.
Returns BuildInfo with status building.
Template.rebuild()
Needs
declaw 1.7.0 or later. Upgrade with pip install -U declaw.build().
ready template, or one whose build is still running, is refused
with ConflictError. Building the same alias again is also refused with a
ConflictError whose message names the template to rebuild.
str
required
The template to rebuild. Only a template whose last build failed.
Callable[[str], None] | None
default:"None"
Called with each new line of build output while waiting.
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.
float
default:"3600"
Seconds to wait for the build to finish. It keeps running after a
TimeoutError; follow it with get_build_status().BuildInfo with status completed.
Raises BuildError (the rebuild failed; the error carries its logs),
ConflictError (the template is not in the failed state), TimeoutError.
Template.rebuild_in_background()
Queue a rebuild of a failed template and return as soon as the server has
accepted it, with status building. Follow it with get_build_status().
Template.rebuild() except on_build_logs and
build_timeout, which only apply while waiting.
Returns BuildInfo with status building.
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.
TemplateBuildStatus
Data models
BuildInfo
TemplateBuildStatus
CopyItem
AsyncTemplate
UseAsyncTemplate for async applications. It has the same static methods as
Template but all are coroutines:
await AsyncTemplate.build(...), await AsyncTemplate.build_in_background(...), await AsyncTemplate.rebuild(...), await AsyncTemplate.rebuild_in_background(...), await AsyncTemplate.get_build_status(...).