Template class creates and manages reusable sandbox base images. Templates are built once and then used to launch any number of identically configured sandboxes in seconds.
See the Templates overview for concepts, or jump to the Create a template guide for the end-to-end flow.
Import
Factory methods
Template.create
Register a new template and queue its first build. Returns as soon as the template row exists and a build_id is assigned - the build itself runs asynchronously. Call waitUntilReady to block until the build finishes.
| Option | Type | Description |
|---|---|---|
name | string | Required. Team-scoped identifier. Must not start with superserve/. Names are unique per team among non-deleted templates and are released for reuse the moment a template is deleted. |
from / from_ | string | Required. OCI base image (e.g. python:3.11). See BuildSpec. |
vcpu | number | 1-4. Default 1. |
memoryMib / memory_mib | number | 256-4096. Default 1024. |
diskMib / disk_mib | number | 1024-8192. Default 4096. |
steps | BuildStep[] | Ordered build steps. |
startCmd / start_cmd | string | Long-running process captured in the snapshot. |
readyCmd / ready_cmd | string | Readiness probe polled every 2s after startCmd. |
apiKey / api_key | string | Overrides SUPERSERVE_API_KEY. |
baseUrl / base_url | string | Overrides SUPERSERVE_BASE_URL. |
signal | AbortSignal | TypeScript only - abort the creation request. |
SandboxError if the API response is missing build_id.
Template.connect
Load an existing template by UUID.
Template.list
List all templates visible to the authenticated team (includes system templates).
TemplateInfo.
Template.deleteById / Template.delete_by_id
Delete a template by UUID without instantiating it. Idempotent on 404.
ConflictError if any non-destroyed sandbox still references the template. The template’s name is released for reuse as soon as the call succeeds.
Methods on template
getInfo / get_info
Fetch the current server-side state. Returns a fresh TemplateInfo - the template’s own properties are snapshots and are not mutated.
waitUntilReady / wait_until_ready
Block until the current build reaches a terminal status. The SDK polls GET /templates/{id}/builds/{buildId} for the authoritative build status — SSE is used only for live log delivery when onLog / on_log is provided, never to detect termination. Returns a refreshed TemplateInfo with status = "ready".
| Option | Type | Description |
|---|---|---|
onLog / on_log | (ev: BuildLogEvent) => void | Called for every SSE log event. |
signal | AbortSignal | TypeScript only - aborts the stream and any pending poll. |
pollIntervalMs | number | TypeScript only. Build status poll interval. Default 2000. |
poll_interval_s | float | Python only. Build status poll interval. Default 2.0. |
BuildErrorif the build transitions tofailed. The backend’serror_messagefollows a"<code>: <detail>"convention; the SDK splits it soBuildError.codeis the stable prefix andBuildError.messageis the human-readable detail. See BuildSpec: Build error codes.ConflictErrorif the build iscancelled
streamBuildLogs / stream_build_logs
Pure SSE stream of build logs. The promise resolves when the stream closes. Does not wait for a terminal status - use waitUntilReady for that.
| Option | Type | Description |
|---|---|---|
onEvent / on_event | (ev: BuildLogEvent) => void | Required. Called for every event. |
buildId / build_id | string | Target build. Defaults to latestBuildId / latest_build_id. |
signal | AbortSignal | TypeScript only - aborts the stream. |
SandboxError if no buildId is supplied and the template has no latestBuildId.
rebuild
Queue a new build for this template. Returns the new TemplateBuildInfo. Idempotent: if an in-flight build already matches the same configuration, the existing build is returned.
listBuilds / list_builds
List recent builds for this template, newest first.
TemplateBuildInfo.
getBuild / get_build
Fetch a single build by ID.
cancelBuild / cancel_build
Cancel an in-flight build. Idempotent - no-op for builds already in a terminal state, and for 404.
delete
Delete this template. Idempotent on 404.
ConflictError if any non-destroyed sandbox still references the template - destroy those sandboxes first.
Properties on template
All properties are read-only snapshots taken at construction. Call getInfo() / get_info() to refresh.
| Property | Type | Description |
|---|---|---|
id | string | Template UUID. |
name | string | Team-scoped identifier. |
teamId / team_id | string | Owning team UUID. |
status | TemplateStatus | Status at construction time. |
vcpu | number | vCPU count the template boots with. |
memoryMib / memory_mib | number | Memory the template boots with. |
diskMib / disk_mib | number | Disk the template boots with. |
sizeBytes? / size_bytes? | number | Snapshot size in bytes, once built. |
errorMessage? / error_message? | string | Last build’s error message, if any. |
createdAt / created_at | Date / datetime | When the template row was created. |
builtAt? / built_at? | Date / datetime | When the latest successful build finished. |
latestBuildId? / latest_build_id? | string | Most recent build UUID. |
Types
TemplateStatus
pending- template exists; first build is queuedbuilding- a build is in progressready- at least one successful build exists; sandboxes can boot from this templatefailed- the latest build failed; rebuild or fix the spec
TemplateBuildStatus
TemplateInfo
TemplateBuildInfo
BuildLogEvent
stream == "system" events are status messages from the build runner (build-step boundaries, snapshot progress). Filter them out when rendering to a user-facing console. finished: true marks the last event in a stream and carries the terminal status.
BuildStep
A discriminated union - exactly one of run / env / workdir / user must be set per step. See BuildSpec: Steps for semantics.
BuildError
Thrown by waitUntilReady / wait_until_ready when the build transitions to failed.
error_message follows a "<code>: <detail>" convention (e.g. "image_too_large: image is too large for the requested disk_mib"). The SDK splits it so code holds the prefix and the error message holds the detail. When the backend doesn’t include a prefix, code falls back to "build_failed" and the message falls back to "Template build failed".
See the full list of build error codes and the general Errors reference.
Retries
GET and DELETE requests (includingTemplate.list, Template.connect, getInfo, listBuilds, getBuild, cancelBuild, delete, deleteById) auto-retry on 429, 502, 503, 504, and network errors with exponential backoff + jitter (3 attempts max). POST requests (create, rebuild) are not retried - the SDK surfaces the error so you can decide.
Errors
Template methods commonly raise:AuthenticationError- missing or invalid API keyValidationError- bad request body (invalid name, unsupported base image, steps with multiple keys)NotFoundError- template or build doesn’t exist (exceptdelete/deleteById/cancelBuild, which swallow 404)ConflictError- template has dependent sandboxes (on delete) or build was cancelled (onwaitUntilReady)BuildError- build transitioned tofailed(fromwaitUntilReadyonly)ServerError- platform error