template

package
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 27 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package template provides a fluent builder and a Client for building and managing E2B sandbox templates. It mirrors the public surface of the Python Template and JS TemplateBase classes while preserving legacy endpoints for self-hosted E2B deployments.

A Builder accumulates instructions and can be serialized with ToDockerfile or ToJSON. To register a template with the E2B backend, construct a Client via NewClient and call Build / BuildStream / BuildInBackground (or BuildV2 / BuildStreamV2 / BuildInBackgroundV2 on legacy self-hosted E2B). Client methods honor context cancellation and are safe for concurrent use; a *Builder is not — construct one per goroutine.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultLogger

func DefaultLogger(w io.Writer) func(LogEntry)

DefaultLogger returns a function that prints log entries to w (or os.Stderr when w is nil). Suitable for BuildOptions.OnBuildLogs.

Types

type AptOption

type AptOption func(*aptOpts)

AptOption configures Builder.AptInstall.

func WithAptFixMissing

func WithAptFixMissing() AptOption

WithAptFixMissing passes --fix-missing to apt-get install.

func WithAptNoInstallRecommends

func WithAptNoInstallRecommends() AptOption

WithAptNoInstallRecommends passes --no-install-recommends to apt-get install.

type AssignTagsOptions added in v0.1.4

type AssignTagsOptions struct {
	// IdempotencyKey is an optional team-scoped key (1..255 lowercase ASCII
	// letters, digits, or hyphens) sent as the Idempotency-Key request header.
	IdempotencyKey string
}

AssignTagsOptions configures optional parameters on Client.AssignTagsWithOptions.

type BuildError

type BuildError struct {
	e2b.BaseError
	Op         string
	TemplateID string
	BuildID    string
	Step       string
	Message    string
	LogTail    []LogEntry
	Err        error
}

BuildError describes a failure during a server-side template build or template management API operation.

BuildError embeds e2b.BaseError so it satisfies e2b.Error and exposes HTTPStatus() / ErrorCode() when decoded from an API HTTP response. Unwrap() exposes both e2b.ErrTemplateBuild and the underlying error (if any) so errors.Is and errors.As inspect both sentinels and typed API errors.

func (*BuildError) Error

func (e *BuildError) Error() string

func (*BuildError) Unwrap

func (e *BuildError) Unwrap() []error

type BuildEvent

type BuildEvent struct {
	Log  *LogEntry
	Done *BuildInfo
	Err  error
}

BuildEvent is one emission from Client.BuildStream. Exactly one of Log, Done, or Err is non-nil at a time. The channel closes after emitting a terminal Done or Err.

type BuildInfo

type BuildInfo struct {
	TemplateID string
	BuildID    string
	Name       string
	Tags       []string
}

BuildInfo identifies a completed or in-flight template build. Returned from Client.Build and Client.BuildInBackground.

type BuildLogsOptions

type BuildLogsOptions struct {
	// CursorMs is the starting timestamp in milliseconds. 0 means server default.
	CursorMs int64
	// Limit caps the number of log entries returned (0–1000). 0 means server default.
	Limit int32
	// Direction is "asc" or "desc". Empty means server default.
	Direction string
	// Level filters out entries below this level. Empty means no filter.
	Level LogLevel
	// Source selects the log store ("persistent" or "temporary"). Empty uses server default.
	Source string
}

BuildLogsOptions filters Client.GetBuildLogs.

type BuildOptions

type BuildOptions struct {
	// Name is the template name (or "name:tag" on Build v3). Required.
	Name string
	// Tags assigns additional tags during Build v3 (unsupported on BuildV2).
	Tags []string
	// CPUCount sets the sandbox vCPU count. Leave 0 to use the server/tier default.
	CPUCount int32
	// MaxCPUCount sets the maximum vCPU count for resizable templates (Build v3 only).
	MaxCPUCount *int32
	// MemoryMB sets the sandbox RAM in MiB. Leave 0 to use the server/tier default.
	MemoryMB int32
	// MinFreeDiskMB requests minimum free disk space in MiB after build steps (Build v3 only).
	MinFreeDiskMB *int32
	// SkipCache forces the entire template build to run without cache.
	SkipCache bool
	// PollInterval sets how frequently Build / BuildStream poll build status.
	// Defaults to 200ms when <= 0.
	PollInterval time.Duration
	// IdempotencyKey is an optional key (1..255 lowercase ASCII letters, digits,
	// or hyphens) sent as the Idempotency-Key header on POST /v3/templates and
	// POST /v2/templates/{id}/builds/{buildID} (unless TriggerIdempotencyKey
	// overrides the build-trigger step).
	IdempotencyKey string
	// TriggerIdempotencyKey optionally overrides the Idempotency-Key header sent
	// specifically on POST /v2/templates/{id}/builds/{buildID} when a deployment
	// enforces team-scoped idempotency across both build-create and build-start.
	TriggerIdempotencyKey string
	// OnBuildLogs, when non-nil, is invoked sequentially for every build log
	// entry observed while polling in Build, BuildStream, BuildV2, or BuildStreamV2.
	OnBuildLogs func(LogEntry)
}

BuildOptions captures every caller-tunable parameter of a template build.

type BuildReason

type BuildReason struct {
	Step    string
	Message string
	Logs    []LogEntry
}

BuildReason describes why a build ended in the error state.

type BuildStatus

type BuildStatus struct {
	TemplateID string
	BuildID    string
	Status     BuildStatusValue
	Logs       []LogEntry
	Reason     *BuildReason
}

BuildStatus is the server-reported state of a template build.

type BuildStatusOptions added in v0.1.4

type BuildStatusOptions struct {
	// LogsOffset is the starting build log index. 0 starts from the beginning.
	LogsOffset int
	// Limit caps the number of log entries returned (0–100). 0 uses server default.
	Limit int32
	// Level filters out entries below this level. Empty means no filter.
	Level LogLevel
}

BuildStatusOptions configures Client.GetBuildStatusWithOptions.

type BuildStatusValue

type BuildStatusValue string

BuildStatusValue enumerates the possible states of a running template build, mirroring the upstream API enum.

const (
	BuildStatusBuilding BuildStatusValue = "building"
	BuildStatusWaiting  BuildStatusValue = "waiting"
	BuildStatusReady    BuildStatusValue = "ready"
	BuildStatusError    BuildStatusValue = "error"
)

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder constructs a template. A *Builder is not safe for concurrent use — construct one per goroutine, or fully finalize it with SetStartCmd / SetReadyCmd (which return a *FinalBuilder) before handing the result off.

func New

func New() *Builder

New returns an empty builder initialized with the default "e2bdev/base" base image. Use FromImage, FromTemplate, or FromDockerfileContent to select another base.

func (*Builder) AddMCPServer

func (b *Builder) AddMCPServer(servers []string) *Builder

AddMCPServer adds one or more MCP servers using mcp-gateway. Only valid when the builder was initialized with FromTemplate("mcp-gateway"); the error is captured on the builder and surfaced at serialize().

func (*Builder) AptInstall

func (b *Builder) AptInstall(packages []string, opts ...AptOption) *Builder

AptInstall emits the Python SDK's canonical "apt-get update && apt-get install -y ..." one-liner so the update and install share a single cache layer and partial updates never go stale.

func (*Builder) BaseImage

func (b *Builder) BaseImage() string

BaseImage returns the base image (empty when building on an E2B template).

func (*Builder) BaseTemplate

func (b *Builder) BaseTemplate() string

BaseTemplate returns the base template ID (empty when building on an image).

func (*Builder) BetaDevContainerPrebuild

func (b *Builder) BetaDevContainerPrebuild(dir string) *Builder

BetaDevContainerPrebuild runs a devcontainer build during the template build. Only valid when the builder was initialized with FromTemplate("devcontainer").

func (*Builder) BetaSetDevContainerStart

func (b *Builder) BetaSetDevContainerStart(dir string) *FinalBuilder

BetaSetDevContainerStart wires the devcontainer-specific start+ready commands to a workspace directory. Requires FromTemplate("devcontainer").

func (*Builder) BunInstall

func (b *Builder) BunInstall(packages []string, opts ...BunOption) *Builder

BunInstall emits a RUN that installs JS/TS packages via bun. Nil/empty packages produce a bare "bun install".

func (*Builder) Copy

func (b *Builder) Copy(src, dst string, opts ...CopyOption) *Builder

Copy adds a COPY instruction from the template build context. The Args slice carries four positional slots — src, dst, user, mode. When mode is unset the slot stays "", otherwise it is formatted as a zero-padded 4-digit octal string.

func (*Builder) CopyItems

func (b *Builder) CopyItems(items []CopyItem) *Builder

CopyItems adds a COPY instruction for each item, translating struct fields to CopyOptions so validation and defaults match single Copy calls.

func (*Builder) Entrypoint

func (b *Builder) Entrypoint(cmd string) *Builder

Entrypoint sets the container entrypoint. Retained for Dockerfile-level parity; the server build API has no direct ENTRYPOINT step.

func (*Builder) Env

func (b *Builder) Env(key, value string) *Builder

Env sets an environment variable.

func (*Builder) Expose

func (b *Builder) Expose(port int) *Builder

Expose documents a port.

func (*Builder) FromAWSRegistry

func (b *Builder) FromAWSRegistry(image, accessKeyID, secretAccessKey, region string) *Builder

FromAWSRegistry sets the base image and configures AWS ECR authentication.

func (*Builder) FromAlpineImage added in v0.1.4

func (b *Builder) FromAlpineImage(variant string) *Builder

FromAlpineImage starts a template from an official Alpine image. The default variant is "3.24".

func (*Builder) FromArchImage added in v0.1.4

func (b *Builder) FromArchImage(variant string) *Builder

FromArchImage starts a template from an official Arch Linux image. The default variant is "latest".

func (*Builder) FromBaseImage

func (b *Builder) FromBaseImage() *Builder

FromBaseImage resets to the default e2bdev/base image.

func (*Builder) FromBunImage

func (b *Builder) FromBunImage(variant string) *Builder

FromBunImage starts a template from an official Bun image. The default variant is "latest".

func (*Builder) FromDebianImage

func (b *Builder) FromDebianImage(variant string) *Builder

FromDebianImage starts a template from an official Debian image. The default variant is "stable".

func (*Builder) FromDockerfile

func (b *Builder) FromDockerfile(contents string) *Builder

FromDockerfile parses inline Dockerfile content. Deprecated: prefer FromDockerfileContent (clearer name) or FromDockerfileFile.

func (*Builder) FromDockerfileContent

func (b *Builder) FromDockerfileContent(content string) *Builder

FromDockerfileContent parses inline Dockerfile text and applies the instructions to this builder. Supported instructions: FROM, RUN, COPY (two-token form), WORKDIR, USER, ENV. Others are silently ignored.

func (*Builder) FromDockerfileFile

func (b *Builder) FromDockerfileFile(path string) *Builder

FromDockerfileFile reads a file from disk and parses it with FromDockerfileContent.

func (*Builder) FromFedoraImage added in v0.1.4

func (b *Builder) FromFedoraImage(variant string) *Builder

FromFedoraImage starts a template from an official Fedora image. The default variant is "44".

func (*Builder) FromGCPRegistry

func (b *Builder) FromGCPRegistry(image, serviceAccountJSON string) *Builder

FromGCPRegistry sets the base image and configures GCP Artifact/Container Registry authentication via a service-account JSON blob.

func (*Builder) FromGoImage

func (b *Builder) FromGoImage(tag string) *Builder

FromGoImage uses the official golang image (default tag "1").

func (*Builder) FromImage

func (b *Builder) FromImage(image string, creds ...RegistryCredentials) *Builder

FromImage sets the base Docker image. An optional RegistryCredentials argument supplies basic-auth credentials for a private registry; only the first value is consulted. When both Username and Password are empty the registry config is left nil.

func (*Builder) FromNodeImage

func (b *Builder) FromNodeImage(tag string) *Builder

FromNodeImage uses the official node image (default tag "lts").

func (*Builder) FromPythonImage

func (b *Builder) FromPythonImage(tag string) *Builder

FromPythonImage uses the official python image with the given tag (default "3").

func (*Builder) FromTemplate

func (b *Builder) FromTemplate(templateID string) *Builder

FromTemplate bases this template on another E2B template.

func (*Builder) FromUbuntuImage

func (b *Builder) FromUbuntuImage(variant string) *Builder

FromUbuntuImage starts a template from an official Ubuntu image. The default variant is "latest".

func (*Builder) GitClone

func (b *Builder) GitClone(url string, opts ...GitCloneOption) *Builder

GitClone emits a RUN that clones the given URL. Branch, depth, and path options append their tokens in the order git expects (branch adds three tokens, depth adds two, path adds one), shell-quoting unsafe tokens.

func (*Builder) MakeDir

func (b *Builder) MakeDir(paths []string, opts ...MkdirOption) *Builder

MakeDir creates one or more directories inside the template during build.

func (b *Builder) MakeSymlink(src, dest string, opts ...SymlinkOption) *Builder

MakeSymlink creates a symbolic link at dest pointing to src inside the template during build.

func (*Builder) NpmInstall

func (b *Builder) NpmInstall(packages []string, opts ...NpmOption) *Builder

NpmInstall emits a RUN that installs Node packages via npm. Nil/empty packages produce a bare "npm install" (install dependencies from package.json).

func (*Builder) PipInstall

func (b *Builder) PipInstall(packages []string, opts ...PipOption) *Builder

PipInstall emits a RUN that installs Python packages via pip. With a nil or empty packages slice it falls back to "pip install ." (install current directory). The default user is root; WithPipUserInstall clears that and appends --user.

func (*Builder) ReadyCmdString

func (b *Builder) ReadyCmdString() string

ReadyCmdString returns the configured readiness command.

func (*Builder) Remove

func (b *Builder) Remove(paths []string, opts ...RemoveOption) *Builder

Remove deletes files or directories inside the template during build.

func (*Builder) Rename

func (b *Builder) Rename(src, dest string, opts ...RenameOption) *Builder

Rename moves src to dest inside the template during build.

func (*Builder) Run

func (b *Builder) Run(cmd string) *Builder

Run adds a RUN instruction.

func (*Builder) RunCmd

func (b *Builder) RunCmd(cmd string, opts ...RunOption) *Builder

RunCmd appends a RUN instruction for a single shell command, with an optional user selection via WithRunUser.

func (*Builder) RunCmds

func (b *Builder) RunCmds(cmds []string, opts ...RunOption) *Builder

RunCmds joins the commands with " && " and delegates to RunCmd so the server sees a single RUN step.

func (*Builder) SetEnvs

func (b *Builder) SetEnvs(envs map[string]string) *Builder

SetEnvs emits a single ENV instruction whose Args interleave keys and values (k1, v1, k2, v2, ...) sorted ascending by key so Go map iteration order never invalidates build layer caches. An empty or nil map is a no-op.

func (*Builder) SetReadyCmd

func (b *Builder) SetReadyCmd(ready ReadyCmd) *FinalBuilder

SetReadyCmd sets only the readiness check and finalizes the builder.

func (*Builder) SetStartCmd

func (b *Builder) SetStartCmd(cmd string, ready ReadyCmd) *FinalBuilder

SetStartCmd records the command run when a sandbox boots, plus the readiness check to wait on. Pass ReadyCmd{} to opt out of a readiness check.

func (*Builder) SetTag

func (b *Builder) SetTag(tag string) *Builder

SetTag tags the final template (e.g. "my-template:v2").

func (*Builder) SetUser

func (b *Builder) SetUser(user string) *Builder

SetUser emits a USER instruction that switches the default build user.

func (*Builder) SetWorkdir

func (b *Builder) SetWorkdir(path string) *Builder

SetWorkdir emits a WORKDIR instruction with the given path.

func (*Builder) SkipCache

func (b *Builder) SkipCache() *Builder

SkipCache marks all subsequent instructions added to this Builder as force-rebuilt (sticky, matching upstream JS/Python forceNextLayer), invalidating cached layers from this point forward. If a FROM method (FromImage, FromTemplate, etc.) is called after SkipCache, the entire template build is marked Force.

func (*Builder) StartCmd

func (b *Builder) StartCmd() string

StartCmd returns the configured start command.

func (*Builder) Tag

func (b *Builder) Tag() string

Tag returns the tag associated with this template build.

func (*Builder) ToDockerfile

func (b *Builder) ToDockerfile() (string, error)

ToDockerfile serializes the builder to a Dockerfile. Templates based on another E2B template cannot be serialized and return an error.

func (*Builder) ToJSON

func (b *Builder) ToJSON() (string, error)

ToJSON returns the JSON payload that Client.Build would send to the server, pretty-printed. Useful for inspection and debugging.

func (*Builder) WithContext

func (b *Builder) WithContext(dir string) *Builder

WithContext sets the local directory used as the build context for COPY instructions. Subsequent COPY hashing and tar packaging reads files under this path.

func (*Builder) WithIgnore

func (b *Builder) WithIgnore(patterns ...string) *Builder

WithIgnore appends patterns (in .dockerignore syntax) that filter files during COPY hashing and tar packaging.

func (*Builder) Workdir

func (b *Builder) Workdir(path string) *Builder

Workdir sets the working directory. It records a WORKDIR instruction and persists the value for later fluent calls.

type BunOption

type BunOption func(*bunOpts)

BunOption configures Builder.BunInstall.

func WithBunDev

func WithBunDev() BunOption

WithBunDev appends --dev to the bun invocation (bun's equivalent of npm's --save-dev).

func WithBunGlobal

func WithBunGlobal() BunOption

WithBunGlobal appends -g to the bun invocation and sets the user to root.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a server-side template builder and management client. Methods on Client dispatch to the E2B template HTTP API. Safe for concurrent use.

func NewClient

func NewClient(cfg e2b.Config) (*Client, error)

NewClient constructs a Client from cfg, applying environment-variable fallbacks via cfg.Resolve(), wiring ControlPlaneHTTPClient() (with retries and RequestTimeout) for control-plane REST calls, and wiring a dedicated DataPlaneHTTPClient() (no client-wide timeout or control-plane retry wrapper) for presigned layer uploads.

When both APIKey and AccessToken are present on the resolved Config, NewClient keeps X-API-Key on the primary REST client and also prepares a Bearer-only secondary client (never sending both headers on the same request) so legacy self-hosted E2B deployments that require AccessTokenAuth on GET /templates, PATCH /templates/{id}, and DELETE /templates/{id} work seamlessly alongside X-API-Key template builds on a single Client.

func (*Client) AssignTags

func (c *Client) AssignTags(ctx context.Context, target string, tags []string) (*TagInfo, error)

AssignTags assigns one or more tags to an existing template build. For idempotent retries via Idempotency-Key, use AssignTagsWithOptions.

Endpoint: POST /templates/tags Compatibility: E2B Cloud; self-hosted runtime 2026.01..2026.30 (not in < 2026.01).

func (*Client) AssignTagsWithOptions added in v0.1.4

func (c *Client) AssignTagsWithOptions(ctx context.Context, target string, tags []string, opts AssignTagsOptions) (*TagInfo, error)

AssignTagsWithOptions assigns one or more tags to an existing template build, optionally attaching an Idempotency-Key header via opts.IdempotencyKey.

Endpoint: POST /templates/tags Compatibility: E2B Cloud; self-hosted runtime 2026.01..2026.30 (Idempotency-Key honored on E2B Cloud; not in < 2026.01).

func (*Client) Build

func (c *Client) Build(ctx context.Context, b *Builder, opts BuildOptions) (*BuildInfo, error)

Build runs a server-side v3 template build to completion. When opts.OnBuildLogs is set, each live log entry is forwarded to it before Build returns; for channel-based streaming use BuildStream.

Endpoint: POST /v3/templates, GET /templates/{templateID}/files/{hash}, PUT <presigned-url>, POST /v2/templates/{templateID}/builds/{buildID}, GET /templates/{templateID}/builds/{buildID}/status Compatibility: E2B Cloud; self-hosted runtime 2025.44..2026.30 (use BuildV2 on < 2025.44).

func (*Client) BuildInBackground

func (c *Client) BuildInBackground(ctx context.Context, b *Builder, opts BuildOptions) (*BuildInfo, error)

BuildInBackground kicks off a v3 template build without polling for completion. Poll progress via GetBuildStatus using the returned BuildInfo.

Endpoint: POST /v3/templates, GET /templates/{templateID}/files/{hash}, PUT <presigned-url>, POST /v2/templates/{templateID}/builds/{buildID} Compatibility: E2B Cloud; self-hosted runtime 2025.44..2026.30 (use BuildInBackgroundV2 on < 2025.44).

func (*Client) BuildInBackgroundV2

func (c *Client) BuildInBackgroundV2(ctx context.Context, b *Builder, opts BuildOptions) (*BuildInfo, error)

BuildInBackgroundV2 is the POST /v2/templates counterpart of BuildInBackground. POST /v2/templates is retired (returns 410 Gone) on E2B Cloud, while still actively served on self-hosted runtime <= 2026.30 (and required on self-hosted runtime < 2025.44 where POST /v3/templates does not exist). Never falls back to POST /v3/templates.

Endpoint: POST /v2/templates, GET /templates/{templateID}/files/{hash}, PUT <presigned-url>, POST /v2/templates/{templateID}/builds/{buildID} Compatibility: actively served on self-hosted runtime <= 2026.30 (required on < 2025.44); retired (410 Gone) on E2B Cloud — use BuildInBackground instead.

func (*Client) BuildStream

func (c *Client) BuildStream(ctx context.Context, b *Builder, opts BuildOptions) (<-chan BuildEvent, error)

BuildStream kicks off a v3 template build and returns a channel of BuildEvents. The channel closes after emitting a terminal Done or Err event.

Endpoint: POST /v3/templates, GET /templates/{templateID}/files/{hash}, PUT <presigned-url>, POST /v2/templates/{templateID}/builds/{buildID}, GET /templates/{templateID}/builds/{buildID}/status Compatibility: E2B Cloud; self-hosted runtime 2025.44..2026.30 (use BuildStreamV2 on < 2025.44).

func (*Client) BuildStreamV2

func (c *Client) BuildStreamV2(ctx context.Context, b *Builder, opts BuildOptions) (<-chan BuildEvent, error)

BuildStreamV2 is the POST /v2/templates counterpart of BuildStream. POST /v2/templates is retired (returns 410 Gone) on E2B Cloud, while still actively served on self-hosted runtime <= 2026.30 (and required on self-hosted runtime < 2025.44 where POST /v3/templates does not exist). Never falls back to POST /v3/templates.

Endpoint: POST /v2/templates, GET /templates/{templateID}/files/{hash}, PUT <presigned-url>, POST /v2/templates/{templateID}/builds/{buildID}, GET /templates/{templateID}/builds/{buildID}/status Compatibility: actively served on self-hosted runtime <= 2026.30 (required on < 2025.44); retired (410 Gone) on E2B Cloud — use BuildStream instead.

func (*Client) BuildV2

func (c *Client) BuildV2(ctx context.Context, b *Builder, opts BuildOptions) (*BuildInfo, error)

BuildV2 is the POST /v2/templates counterpart of Build. Tags, MaxCPUCount, and MinFreeDiskMB are not supported by the v2 request schema and must be unset.

Unlike soft-deprecated v1 routes that remain active, POST /v2/templates is retired (returns 410 Gone) on E2B Cloud, while still actively served on self-hosted runtime <= 2026.30. Use BuildV2 on self-hosted runtime < 2025.44 (where POST /v3/templates does not exist); use Build on E2B Cloud and self-hosted runtime 2025.44..2026.30. Never falls back to POST /v3/templates.

Endpoint: POST /v2/templates, GET /templates/{templateID}/files/{hash}, PUT <presigned-url>, POST /v2/templates/{templateID}/builds/{buildID}, GET /templates/{templateID}/builds/{buildID}/status Compatibility: actively served on self-hosted runtime <= 2026.30 (required on < 2025.44); retired (410 Gone) on E2B Cloud — use Build instead.

func (*Client) Config added in v0.1.4

func (c *Client) Config() e2b.Config

Config returns a copy of the resolved Config backing this Client. Map and pointer fields are deep-copied so mutating the returned Config cannot race with concurrent requests.

func (*Client) CountTags added in v0.1.4

func (c *Client) CountTags(ctx context.Context, templateID string) (int64, error)

CountTags returns the number of distinct tags on the template that have at least one ready build.

Endpoint: GET /templates/{templateID}/tags/count Compatibility: E2B Cloud only (not in self-hosted runtime <= 2026.30).

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, templateID string) error

Delete removes a template by ID. Returns an error on non-2xx responses (including 404 Not Found; see Destroy for 404-tolerant deletion).

Endpoint: DELETE /templates/{templateID} Compatibility: E2B Cloud; self-hosted runtime <= 2026.30.

func (*Client) Destroy added in v0.1.4

func (c *Client) Destroy(ctx context.Context, templateID string) (bool, error)

Destroy deletes a template by ID, returning (false, nil) when the template was already absent (404 Not Found) and (true, nil) when deleted — matching upstream Template.delete and e2b.Client.Kill / volume.Client.Destroy.

Endpoint: DELETE /templates/{templateID} Compatibility: E2B Cloud; self-hosted runtime <= 2026.30.

func (*Client) Exists

func (c *Client) Exists(ctx context.Context, alias string) (bool, error)

Exists returns true if a template with the given alias/name exists (200 OK or 403 Forbidden when owned by another team). 404 means it does not exist; other non-2xx status codes are returned as errors.

Endpoint: GET /templates/aliases/{alias} Compatibility: E2B Cloud; self-hosted runtime 2026.02..2026.30 (not in < 2026.02).

func (*Client) Get

func (c *Client) Get(ctx context.Context, templateID string, opts GetOptions) (*TemplateDetail, error)

Get returns template metadata and one page of build history for a single template, populating TemplateDetail.NextToken from the x-next-token response header when further build pages exist.

Endpoint: GET /templates/{templateID} Compatibility: E2B Cloud; self-hosted runtime 2025.45..2026.30 (not in < 2025.45).

func (*Client) GetBuildLogs

func (c *Client) GetBuildLogs(ctx context.Context, templateID, buildID string, opts BuildLogsOptions) ([]LogEntry, error)

GetBuildLogs fetches structured build logs for a specific build.

Endpoint: GET /templates/{templateID}/builds/{buildID}/logs Compatibility: E2B Cloud; self-hosted runtime 2025.50..2026.30 (not in < 2025.50; use GetBuildStatus logs).

func (*Client) GetBuildStatus

func (c *Client) GetBuildStatus(ctx context.Context, info BuildInfo, logsOffset int) (*BuildStatus, error)

GetBuildStatus fetches the current status and incremental log entries of an in-flight or completed template build.

Endpoint: GET /templates/{templateID}/builds/{buildID}/status Compatibility: E2B Cloud; self-hosted runtime <= 2026.30.

func (*Client) GetBuildStatusWithOptions added in v0.1.4

func (c *Client) GetBuildStatusWithOptions(ctx context.Context, info BuildInfo, opts BuildStatusOptions) (*BuildStatus, error)

GetBuildStatusWithOptions fetches the current status of a template build with optional log offset, limit, and minimum severity level filters.

Endpoint: GET /templates/{templateID}/builds/{buildID}/status Compatibility: E2B Cloud; self-hosted runtime <= 2026.30.

func (*Client) GetTagAssignments added in v0.1.4

func (c *Client) GetTagAssignments(ctx context.Context, templateID, tag string, opts TagAssignmentsOptions) (*TagAssignmentsPage, error)

GetTagAssignments lists the ready assignment events for a single tag on the template, newest first, with keyset cursor pagination.

Endpoint: GET /templates/{templateID}/tags/{tag}/assignments Compatibility: E2B Cloud only (not in self-hosted runtime <= 2026.30).

func (*Client) GetTags

func (c *Client) GetTags(ctx context.Context, templateID string) ([]TemplateTag, error)

GetTags returns every tag associated with a template.

Endpoint: GET /templates/{templateID}/tags Compatibility: E2B Cloud; self-hosted runtime 2026.07..2026.30 (not in < 2026.07).

func (*Client) List

func (c *Client) List(ctx context.Context, opts ListOptions) ([]Template, error)

List returns every template visible to the caller via the unpaginated v1 endpoint. Pass opts.TeamID to restrict the result to a specific team.

Although marked deprecated in OpenAPI since runtime 2026.26 (because it is unpaginated and returns 400 when a team exceeds 5000 templates), GET /templates remains actively served on both E2B Cloud and all self-hosted runtime <= 2026.30. Use List / ListV1 on self-hosted runtime < 2026.26 (where GET /v2/templates does not exist); prefer ListV2 / ListAllV2 on E2B Cloud and runtime 2026.26..2026.30.

Endpoint: GET /templates Compatibility: E2B Cloud and self-hosted runtime <= 2026.30 (actively served everywhere; soft-deprecated in OpenAPI since runtime 2026.26 in favor of ListV2, required on self-hosted runtime < 2026.26).

func (*Client) ListAllV2 added in v0.1.4

func (c *Client) ListAllV2(ctx context.Context, opts ListV2Options) ([]Template, error)

ListAllV2 drains every page from GET /v2/templates and returns all matching templates.

Endpoint: GET /v2/templates Compatibility: E2B Cloud; self-hosted runtime 2026.26..2026.30 (use List / ListV1 on < 2026.26).

func (*Client) ListDefault added in v0.1.4

func (c *Client) ListDefault(ctx context.Context) ([]Template, error)

ListDefault lists the platform's default templates ordered by template ID.

Endpoint: GET /default-templates Compatibility: E2B Cloud only (not in self-hosted runtime <= 2026.30).

func (*Client) ListTagGroups added in v0.1.4

func (c *Client) ListTagGroups(ctx context.Context, templateID string, opts TagGroupsOptions) (*TagGroupsPage, error)

ListTagGroups lists the template's tags that have at least one ready build, each with its most recent ready assignments, paginated via a keyset cursor.

Endpoint: GET /templates/{templateID}/tags/groups Compatibility: E2B Cloud only (not in self-hosted runtime <= 2026.30).

func (*Client) ListV1 added in v0.1.4

func (c *Client) ListV1(ctx context.Context, opts ListOptions) ([]Template, error)

ListV1 is an explicit generation-suffixed alias for List, calling the unpaginated GET /templates endpoint.

Although marked deprecated in OpenAPI since runtime 2026.26 in favor of cursor-paginated GET /v2/templates (ListV2), GET /templates remains actively served on both E2B Cloud and all self-hosted runtime <= 2026.30, and is required on self-hosted runtime < 2026.26 where GET /v2/templates does not exist.

Endpoint: GET /templates Compatibility: E2B Cloud and self-hosted runtime <= 2026.30 (actively served everywhere; soft-deprecated in OpenAPI since runtime 2026.26 in favor of ListV2, required on self-hosted runtime < 2026.26).

func (*Client) ListV2 added in v0.1.4

ListV2 returns a cursor-based TemplatePaginator backed by GET /v2/templates. No network request is issued until the first NextItems call.

Endpoint: GET /v2/templates Compatibility: E2B Cloud; self-hosted runtime 2026.26..2026.30 (use List / ListV1 on < 2026.26).

func (*Client) RemoveTags

func (c *Client) RemoveTags(ctx context.Context, name string, tags []string) error

RemoveTags removes one or more tags from a template.

Endpoint: DELETE /templates/tags Compatibility: E2B Cloud; self-hosted runtime 2026.01..2026.30 (not in < 2026.01).

func (*Client) SetPublic

func (c *Client) SetPublic(ctx context.Context, templateID string, public bool) ([]string, error)

SetPublic toggles the template's public visibility flag via PATCH /v2/templates/{templateID}. Returns the current names (namespace/alias format when namespaced).

Endpoint: PATCH /v2/templates/{templateID} Compatibility: E2B Cloud; self-hosted runtime 2026.05..2026.30 (use SetPublicV1 on < 2026.05).

func (*Client) SetPublicV1

func (c *Client) SetPublicV1(ctx context.Context, templateID string, public bool) error

SetPublicV1 toggles template public visibility via PATCH /templates/{templateID}. Unlike SetPublic (PATCH /v2/templates/{templateID}), the v1 endpoint returns an empty response body rather than the template's updated names.

Although marked deprecated in OpenAPI since runtime 2026.05 in favor of SetPublic, PATCH /templates/{templateID} remains actively served on both E2B Cloud and all self-hosted runtime <= 2026.30. Use SetPublicV1 on self-hosted runtime < 2026.05 (where PATCH /v2/templates/{templateID} does not exist); prefer SetPublic on E2B Cloud and runtime 2026.05..2026.30.

Endpoint: PATCH /templates/{templateID} Compatibility: E2B Cloud and self-hosted runtime <= 2026.30 (actively served everywhere; soft-deprecated in OpenAPI since runtime 2026.05 in favor of SetPublic, required on self-hosted runtime < 2026.05).

func (*Client) TagExists added in v0.1.4

func (c *Client) TagExists(ctx context.Context, templateID, tag string) (*TagExistsResult, error)

TagExists checks whether a tag on the given template has at least one ready build, returning both Exists and the server's NormalizedTag.

Endpoint: GET /templates/{templateID}/tags/exists Compatibility: E2B Cloud only (not in self-hosted runtime <= 2026.30).

type CopyItem

type CopyItem struct {
	Src             string
	Dest            string
	User            string
	Mode            os.FileMode
	ForceUpload     bool
	ResolveSymlinks *bool
}

CopyItem mirrors the Python SDK's CopyItem dict. All fields except Src and Dest are optional.

type CopyOption

type CopyOption func(*copyOpts)

CopyOption is a functional option for Copy.

func WithCopyForceUpload

func WithCopyForceUpload() CopyOption

WithCopyForceUpload forces re-upload of the COPY layer even when a matching hash already exists on the server.

func WithCopyMode

func WithCopyMode(m os.FileMode) CopyOption

WithCopyMode sets the file mode applied to the copied files.

func WithCopyResolveSymlinks(b bool) CopyOption

WithCopyResolveSymlinks overrides the default symlink resolution behavior for this COPY. Pass true to follow symlinks, false to preserve them.

func WithCopyUser

func WithCopyUser(u string) CopyOption

WithCopyUser sets the owning user for the copied files (USER arg of COPY).

type FinalBuilder

type FinalBuilder struct {
	// contains filtered or unexported fields
}

FinalBuilder is the terminal state of the fluent API. After setting the start/ready commands, callers may only serialize or hand off to the Client.

func (*FinalBuilder) BaseImage added in v0.1.4

func (f *FinalBuilder) BaseImage() string

BaseImage returns the base image (empty when building on an E2B template).

func (*FinalBuilder) BaseTemplate added in v0.1.4

func (f *FinalBuilder) BaseTemplate() string

BaseTemplate returns the base template ID (empty when building on an image).

func (*FinalBuilder) Build added in v0.1.4

func (f *FinalBuilder) Build(ctx context.Context, c *Client, opts BuildOptions) (*BuildInfo, error)

Build delegates a finalized template build to c.Build without requiring a manual f.Builder() unwrap.

Endpoint: POST /v3/templates, GET /templates/{templateID}/files/{hash}, PUT <presigned-url>, POST /v2/templates/{templateID}/builds/{buildID}, GET /templates/{templateID}/builds/{buildID}/status Compatibility: E2B Cloud; self-hosted runtime 2025.44..2026.30 (use BuildV2 on < 2025.44).

func (*FinalBuilder) BuildInBackground added in v0.1.4

func (f *FinalBuilder) BuildInBackground(ctx context.Context, c *Client, opts BuildOptions) (*BuildInfo, error)

BuildInBackground delegates a finalized background template build to c.BuildInBackground.

Endpoint: POST /v3/templates, GET /templates/{templateID}/files/{hash}, PUT <presigned-url>, POST /v2/templates/{templateID}/builds/{buildID} Compatibility: E2B Cloud; self-hosted runtime 2025.44..2026.30 (use BuildInBackgroundV2 on < 2025.44).

func (*FinalBuilder) BuildInBackgroundV2 added in v0.1.4

func (f *FinalBuilder) BuildInBackgroundV2(ctx context.Context, c *Client, opts BuildOptions) (*BuildInfo, error)

BuildInBackgroundV2 delegates a finalized v2 background build to c.BuildInBackgroundV2. POST /v2/templates is actively served on self-hosted runtime <= 2026.30 (required on < 2025.44) and retired (410 Gone) on E2B Cloud.

Endpoint: POST /v2/templates, GET /templates/{templateID}/files/{hash}, PUT <presigned-url>, POST /v2/templates/{templateID}/builds/{buildID} Compatibility: actively served on self-hosted runtime <= 2026.30 (required on < 2025.44); retired (410 Gone) on E2B Cloud — use BuildInBackground instead.

func (*FinalBuilder) BuildStream added in v0.1.4

func (f *FinalBuilder) BuildStream(ctx context.Context, c *Client, opts BuildOptions) (<-chan BuildEvent, error)

BuildStream delegates a finalized streaming template build to c.BuildStream.

Endpoint: POST /v3/templates, GET /templates/{templateID}/files/{hash}, PUT <presigned-url>, POST /v2/templates/{templateID}/builds/{buildID}, GET /templates/{templateID}/builds/{buildID}/status Compatibility: E2B Cloud; self-hosted runtime 2025.44..2026.30 (use BuildStreamV2 on < 2025.44).

func (*FinalBuilder) BuildStreamV2 added in v0.1.4

func (f *FinalBuilder) BuildStreamV2(ctx context.Context, c *Client, opts BuildOptions) (<-chan BuildEvent, error)

BuildStreamV2 delegates a finalized v2 streaming template build to c.BuildStreamV2. POST /v2/templates is actively served on self-hosted runtime <= 2026.30 (required on < 2025.44) and retired (410 Gone) on E2B Cloud.

Endpoint: POST /v2/templates, GET /templates/{templateID}/files/{hash}, PUT <presigned-url>, POST /v2/templates/{templateID}/builds/{buildID}, GET /templates/{templateID}/builds/{buildID}/status Compatibility: actively served on self-hosted runtime <= 2026.30 (required on < 2025.44); retired (410 Gone) on E2B Cloud — use BuildStream instead.

func (*FinalBuilder) BuildV2 added in v0.1.4

func (f *FinalBuilder) BuildV2(ctx context.Context, c *Client, opts BuildOptions) (*BuildInfo, error)

BuildV2 delegates a finalized v2 template build to c.BuildV2. POST /v2/templates is actively served on self-hosted runtime <= 2026.30 (required on < 2025.44) and retired (410 Gone) on E2B Cloud.

Endpoint: POST /v2/templates, GET /templates/{templateID}/files/{hash}, PUT <presigned-url>, POST /v2/templates/{templateID}/builds/{buildID}, GET /templates/{templateID}/builds/{buildID}/status Compatibility: actively served on self-hosted runtime <= 2026.30 (required on < 2025.44); retired (410 Gone) on E2B Cloud — use Build instead.

func (*FinalBuilder) Builder

func (f *FinalBuilder) Builder() *Builder

Builder returns the underlying *Builder.

func (*FinalBuilder) ReadyCmdString added in v0.1.4

func (f *FinalBuilder) ReadyCmdString() string

ReadyCmdString returns the configured readiness command.

func (*FinalBuilder) SetTag added in v0.1.4

func (f *FinalBuilder) SetTag(tag string) *FinalBuilder

SetTag tags the finalized template (e.g. "my-template:v2") without dropping back to *Builder.

func (*FinalBuilder) StartCmd added in v0.1.4

func (f *FinalBuilder) StartCmd() string

StartCmd returns the configured start command.

func (*FinalBuilder) Tag added in v0.1.4

func (f *FinalBuilder) Tag() string

Tag returns the tag associated with this template build.

func (*FinalBuilder) ToDockerfile

func (f *FinalBuilder) ToDockerfile() (string, error)

ToDockerfile delegates to the underlying Builder.

func (*FinalBuilder) ToJSON

func (f *FinalBuilder) ToJSON() (string, error)

ToJSON delegates to the underlying Builder.

type GetOptions

type GetOptions struct {
	NextToken string
	Limit     int32
}

GetOptions paginates the build history returned by Client.Get. Zero value uses server defaults.

type GitCloneOption

type GitCloneOption func(*gitOpts)

GitCloneOption configures Builder.GitClone.

func WithGitBranch

func WithGitBranch(branch string) GitCloneOption

WithGitBranch checks out the given branch via --branch + --single-branch.

func WithGitDepth

func WithGitDepth(depth int) GitCloneOption

WithGitDepth sets the clone depth (shallow clone when > 0).

func WithGitPath

func WithGitPath(path string) GitCloneOption

WithGitPath clones into the given local path.

func WithGitUser

func WithGitUser(user string) GitCloneOption

WithGitUser runs the git clone command as the given user.

type ListOptions

type ListOptions struct {
	// TeamID restricts results to a specific team. Empty means no filter.
	TeamID string
}

ListOptions filters Client.List / Client.ListV1 results. Zero value lists every template visible to the caller.

type ListV2Options added in v0.1.4

type ListV2Options struct {
	// TeamID restricts results to a specific team. Empty means no filter.
	TeamID string
	// Names filters returned templates to those matching any of the given
	// template names, aliases, or IDs (both "alias" and "namespace/alias"
	// forms are matched). Empty means no filter.
	Names []string
	// Limit caps the number of templates fetched per server page. 0 uses the
	// server default (100).
	Limit int32
	// NextToken resumes pagination from a previous page's x-next-token cursor.
	NextToken string
}

ListV2Options filters and paginates Client.ListV2 and Client.ListAllV2.

type LogEntry

type LogEntry struct {
	Level     LogLevel
	Message   string
	Timestamp time.Time
}

LogEntry is one structured line from a template build.

type LogEntryEnd

type LogEntryEnd struct {
	Phase string
	OK    bool
}

LogEntryEnd marks the end of a build phase.

type LogEntryStart

type LogEntryStart struct {
	Phase string
}

LogEntryStart marks the beginning of a build phase.

type LogLevel

type LogLevel string

LogLevel mirrors the upstream log severity enum.

const (
	LogLevelDebug LogLevel = "debug"
	LogLevelInfo  LogLevel = "info"
	LogLevelWarn  LogLevel = "warn"
	LogLevelError LogLevel = "error"
)

type MkdirOption

type MkdirOption func(*mkdirOpts)

MkdirOption configures Builder.MakeDir.

func WithMkdirMode

func WithMkdirMode(m os.FileMode) MkdirOption

WithMkdirMode sets the mode bits passed to mkdir via -m.

func WithMkdirUser

func WithMkdirUser(u string) MkdirOption

WithMkdirUser runs the mkdir command as the given user.

type NpmOption

type NpmOption func(*npmOpts)

NpmOption configures Builder.NpmInstall.

func WithNpmDev

func WithNpmDev() NpmOption

WithNpmDev appends --save-dev to the npm invocation.

func WithNpmGlobal

func WithNpmGlobal() NpmOption

WithNpmGlobal appends -g to the npm invocation and sets the user to root.

type PipOption

type PipOption func(*pipOpts)

PipOption configures Builder.PipInstall.

func WithPipUserInstall

func WithPipUserInstall() PipOption

WithPipUserInstall appends --user to the pip invocation and clears the default user (so the command does not force root).

type ReadyCmd

type ReadyCmd struct {
	// contains filtered or unexported fields
}

ReadyCmd wraps a shell command evaluated during template build to decide when the sandbox has finished starting.

func NewReadyCmd added in v0.1.4

func NewReadyCmd(cmd string) ReadyCmd

NewReadyCmd constructs a ReadyCmd from a custom shell snippet. Pass an empty string (or ReadyCmd{}) to opt out of a readiness check.

func WaitForFile

func WaitForFile(path string) ReadyCmd

WaitForFile checks for the existence of a regular file.

func WaitForPort

func WaitForPort(port int) ReadyCmd

WaitForPort checks whether the given TCP port is listening using ss's exact source-port filter (sport = :<port>) so prefix ports (e.g. 80 vs 8080) never collide.

func WaitForProcess

func WaitForProcess(name string) ReadyCmd

WaitForProcess checks whether a process with the given name is running.

func WaitForTimeoutMs

func WaitForTimeoutMs(ms int) ReadyCmd

WaitForTimeoutMs sleeps for the given number of milliseconds (clamped to at least 1 second).

func WaitForURL

func WaitForURL(url string, statusCode int) ReadyCmd

WaitForURL polls an HTTP endpoint until it returns the expected status code (default 200 when statusCode == 0).

func (ReadyCmd) Cmd

func (r ReadyCmd) Cmd() string

Cmd returns the underlying shell snippet.

type RegistryCredentials

type RegistryCredentials struct {
	Username string
	Password string
}

RegistryCredentials carries basic-auth credentials for a private registry.

type RemoveOption

type RemoveOption func(*removeOpts)

RemoveOption configures Builder.Remove.

func WithRemoveForce

func WithRemoveForce() RemoveOption

WithRemoveForce adds -f to the emitted rm command.

func WithRemoveRecursive

func WithRemoveRecursive() RemoveOption

WithRemoveRecursive adds -r to the emitted rm command.

func WithRemoveUser

func WithRemoveUser(u string) RemoveOption

WithRemoveUser runs the rm command as the given user.

type RenameOption

type RenameOption func(*renameOpts)

RenameOption configures Builder.Rename.

func WithRenameForce

func WithRenameForce() RenameOption

WithRenameForce adds -f to the emitted mv command.

func WithRenameUser

func WithRenameUser(u string) RenameOption

WithRenameUser runs the mv command as the given user.

type RunOption

type RunOption func(*runOpts)

RunOption configures Builder.RunCmd and Builder.RunCmds.

func WithRunUser

func WithRunUser(u string) RunOption

WithRunUser runs the command as the given user.

type SymlinkOption

type SymlinkOption func(*symOpts)

SymlinkOption configures Builder.MakeSymlink.

func WithSymlinkForce

func WithSymlinkForce() SymlinkOption

WithSymlinkForce adds -f to the emitted ln command.

func WithSymlinkUser

func WithSymlinkUser(u string) SymlinkOption

WithSymlinkUser runs the ln command as the given user.

type TagAssignment added in v0.1.4

type TagAssignment struct {
	AssignmentID    string
	BuildID         string
	AssignedAt      time.Time
	BuildCreatedAt  time.Time
	BuildFinishedAt *time.Time
}

TagAssignment represents a single ready tag-assignment event for a template.

type TagAssignmentsOptions added in v0.1.4

type TagAssignmentsOptions struct {
	// Cursor resumes from the NextCursor of a previous TagAssignmentsPage.
	Cursor string
	// Limit caps assignment rows returned per page. 0 uses server default.
	Limit int32
}

TagAssignmentsOptions paginates Client.GetTagAssignments.

type TagAssignmentsPage added in v0.1.4

type TagAssignmentsPage struct {
	Data       []TagAssignment
	NextCursor string
}

TagAssignmentsPage is one keyset-paginated page returned by Client.GetTagAssignments.

type TagExistsResult added in v0.1.4

type TagExistsResult struct {
	Exists        bool
	NormalizedTag string
}

TagExistsResult is returned from Client.TagExists.

type TagGroup added in v0.1.4

type TagGroup struct {
	Tag         string
	Assignments []TagAssignment
	HasMore     bool
}

TagGroup represents one distinct template tag together with its most recent ready assignment events, as returned by Client.ListTagGroups.

type TagGroupsOptions added in v0.1.4

type TagGroupsOptions struct {
	// AssignmentLimit caps ready assignment rows returned per tag. 0 uses server default.
	AssignmentLimit int32
	// TagsLimit caps distinct tags returned per page. 0 uses server default.
	TagsLimit int32
	// TagsCursor resumes from the NextCursor of a previous TagGroupsPage.
	TagsCursor string
	// Search filters tag names by substring (allowed chars: a-z, 0-9, ., _, -).
	Search string
	// Sort selects the tag group ordering. Empty uses server default.
	Sort TagGroupsSort
}

TagGroupsOptions filters and paginates Client.ListTagGroups.

type TagGroupsPage added in v0.1.4

type TagGroupsPage struct {
	Tags       []TagGroup
	NextCursor string
}

TagGroupsPage is one keyset-paginated page returned by Client.ListTagGroups.

type TagGroupsSort added in v0.1.4

type TagGroupsSort string

TagGroupsSort specifies the sort order for Client.ListTagGroups.

const (
	TagGroupsSortLatestDesc TagGroupsSort = "latest_desc"
	TagGroupsSortLatestAsc  TagGroupsSort = "latest_asc"
	TagGroupsSortNameAsc    TagGroupsSort = "name_asc"
	TagGroupsSortNameDesc   TagGroupsSort = "name_desc"
)

type TagInfo

type TagInfo struct {
	BuildID string
	Tags    []string
}

TagInfo is returned from Client.AssignTags and Client.AssignTagsWithOptions.

type Template

type Template struct {
	TemplateID    string
	BuildID       string
	Names         []string
	Aliases       []string
	Description   string
	Public        bool
	IsDefault     bool
	CPUCount      int32
	MaxCPUCount   *int32
	MemoryMB      int32
	DiskSizeMB    int32
	EnvdVersion   string
	BuildStatus   BuildStatusValue
	BuildCount    int32
	SpawnCount    int64
	CreatedAt     time.Time
	UpdatedAt     time.Time
	LastSpawnedAt *time.Time
	CreatedBy     *TemplateUser
}

Template is a single row returned from Client.List, Client.ListV1, Client.ListV2, Client.ListAllV2, and Client.ListDefault. Mirrors the upstream Template schema while keeping internal API types private.

type TemplateBuild

type TemplateBuild struct {
	BuildID     string
	Status      BuildStatusValue
	CPUCount    int32
	MaxCPUCount *int32
	MemoryMB    int32
	DiskSizeMB  *int32
	EnvdVersion string
	CreatedAt   time.Time
	UpdatedAt   time.Time
	FinishedAt  *time.Time
}

TemplateBuild is one historical build entry returned inside TemplateDetail.

type TemplateDetail

type TemplateDetail struct {
	TemplateID    string
	BuildID       string
	Names         []string
	Aliases       []string
	Description   string
	Public        bool
	IsDefault     bool
	CPUCount      int32
	MaxCPUCount   *int32
	MemoryMB      int32
	DiskSizeMB    int32
	EnvdVersion   string
	BuildStatus   BuildStatusValue
	BuildCount    int32
	SpawnCount    int64
	CreatedAt     time.Time
	UpdatedAt     time.Time
	LastSpawnedAt *time.Time
	CreatedBy     *TemplateUser
	Builds        []TemplateBuild
	NextToken     string
}

TemplateDetail is the response from Client.Get: template summary metadata plus one page of its build history and the x-next-token pagination cursor.

type TemplatePaginator added in v0.1.4

type TemplatePaginator struct {
	// contains filtered or unexported fields
}

TemplatePaginator iterates pages of templates from GET /v2/templates using the server's x-next-token response header cursor.

A TemplatePaginator is stateful and not safe for concurrent use.

func (*TemplatePaginator) HasNext added in v0.1.4

func (p *TemplatePaginator) HasNext() bool

HasNext reports whether another page of templates is available. It is true before the first NextItems call; afterwards it reflects the x-next-token header of the most recent response.

func (*TemplatePaginator) NextItems added in v0.1.4

func (p *TemplatePaginator) NextItems(ctx context.Context) ([]Template, error)

NextItems fetches the next page of templates from GET /v2/templates. Once exhausted it returns (nil, nil). When ListV2Options.Names is non-empty, pages whose entries are all filtered out are skipped automatically until a matching item is found or all pages are exhausted.

Endpoint: GET /v2/templates Compatibility: E2B Cloud; self-hosted runtime 2026.26..2026.30 (use List / ListV1 on < 2026.26).

func (*TemplatePaginator) NextToken added in v0.1.4

func (p *TemplatePaginator) NextToken() string

NextToken returns the cursor for the next page, or "" when exhausted. It can be persisted and resumed via ListV2Options.NextToken.

type TemplateTag

type TemplateTag struct {
	Tag       string
	BuildID   string
	CreatedAt time.Time
}

TemplateTag is one row returned from Client.GetTags.

type TemplateUser

type TemplateUser struct {
	ID    string
	Email string
}

TemplateUser identifies the creator of a template.

type UploadError

type UploadError struct {
	e2b.BaseError
	Src, Hash string
	Err       error
}

UploadError describes a failure while uploading a template COPY layer.

UploadError embeds e2b.BaseError so it satisfies e2b.Error and exposes HTTPStatus() / ErrorCode() when decoded from an HTTP response. Unwrap() exposes both e2b.ErrTemplateUpload and the underlying error (if any).

func (*UploadError) Error

func (e *UploadError) Error() string

func (*UploadError) Unwrap

func (e *UploadError) Unwrap() []error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL