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 Create(WithTemplate("my-template")) to boot sandboxes that start from a known state.

TemplateSpec

TemplateSpec defines how to build a sandbox template.

CopyItem


declaw.BuildTemplate()

Build a new template and wait for the build to complete. Builds usually take several minutes; bound the wait with ctx.
Returns (*BuildInfo, error). On success Status is declaw.BuildStatusCompleted. A failed build returns a *BuildError whose message quotes the end of the build output and whose Logs holds all of it. If ctx ends first, the error is ctx.Err() and the returned BuildInfo still carries the BuildID: the build keeps running, and GetBuildStatus or WaitForBuild follows it. Status checks that fail temporarily (5xx, 429, no response) are retried for up to two minutes.

declaw.WaitForBuild()

Wait for a build started with BuildTemplateBackground to finish, passing each new line of build output to a callback. It returns like BuildTemplate.
The server keeps the newest 2,000 lines of a build’s output; if more arrive between two checks, a ... [earlier build output truncated] line marks the gap. Returns (*BuildInfo, error)

declaw.BuildTemplateBackground()

Start a template build and return immediately without waiting for completion.
Returns (*BuildInfo, error) with Status declaw.BuildStatusBuilding.

declaw.RebuildTemplate()

Needs github.com/declaw-ai/declaw-go v0.8.0 or later. Upgrade with go get github.com/declaw-ai/declaw-go@latest.
Retry a template whose build failed, and wait for the rebuild like BuildTemplate. The rebuild reuses the template’s stored spec.
Templates are immutable once built, so a ready template, or one whose build is still running, is refused with *ConflictError. A failed template keeps its alias: BuildTemplate with the same alias is refused with a *ConflictError whose message names the template to rebuild. Returns (*BuildInfo, error) — the completed build, a *BuildError for a failed one, or ctx’s error once ctx ends (the build keeps running).

declaw.RebuildTemplateBackground()

Queue a rebuild of a failed template and return as soon as the server has accepted it, with status building. Follow it with WaitForBuild or GetBuildStatus.
Returns (*BuildInfo, error)

declaw.GetBuildStatus()

Poll the status of a background build.
Returns (*BuildInfo, error)

declaw.ListTemplates()

List all templates owned by the caller.
Returns ([]TemplateInfo, error)

declaw.GetTemplate()

Get information about a specific template.
Returns (*TemplateInfo, error)

declaw.DeleteTemplate()

Delete a template by its ID.
Returns error

Data models

BuildInfo

TemplateInfo


Using a template in Create()

Once a template is built, reference it by alias:

Polling a background build