sandbox

package
v0.24.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 11 Imported by: 3 modules, 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 sandbox is the execution boundary of the kernel: the Sandbox interface a scope's workspace operations run against, and the fail-closed backend registry behind OpenSandbox. Backends report their capabilities honestly - unsupported operations return ErrUnsupported rather than pretending - and Capture/Diff never mutate the caller's index. The git backend (in-place and detached-worktree modes) ships as the subpackage sandbox/git in the core module. Other backends are host-supplied: any type implementing Sandbox can register itself with RegisterSandbox.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoSandbox = errors.New("goatherd: scope has no sandbox")

ErrNoSandbox is returned when a workspace or checkpoint operation is attempted on a scope that was created without a sandbox. Pure-causal scopes (no filesystem) are valid; only workspace operations are rejected.

View Source
var ErrUnknownSandboxBackend = errors.New("goatherd: unknown sandbox backend")

ErrUnknownSandboxBackend is the sentinel behind UnknownSandboxBackendError, so callers can errors.Is(err, ErrUnknownSandboxBackend) without matching strings.

View Source
var ErrUnsupported = errors.New("goatherd: sandbox capability not supported")

ErrUnsupported is returned by a Sandbox method whose capability is false according to Capabilities. Callers should check Capabilities before calling an optional method rather than relying on the error, but backends return it so a misconfigured caller fails loudly instead of silently doing nothing.

Functions

func RegisterSandbox

func RegisterSandbox(backend string, f SandboxFactory)

RegisterSandbox registers a backend for OpenSandbox. Intended for init()-time self-registration (the sandbox/git backend) and host wiring (importing a backend module and registering it under its Backend() name).

func SandboxBackends

func SandboxBackends() []string

SandboxBackends lists the registered backend names, sorted, for config diagnostics and doctor output.

Types

type Addressed

type Addressed interface {
	// Address returns the backend's durable address as a normalized
	// absolute path.
	Address() string
}

Addressed is an optional Sandbox capability: the backend's durable workspace address — the worktree path for a git worktree, the repository path for a materializer, the container workspace path for a path-addressed container backend. Recovery records it in the fork payload and hands it back to the host's resolver, so an isolated child's substrate is re-adoptable from the trace alone (plan 06, U2).

The address must be a normalized absolute path: a raw relative path persisted in a trace and replayed after a restart under a different working directory would address the wrong location, and recovery rejects a recorded non-absolute address loudly. A backend whose identity is not a path must not implement this interface yet — its handle could not survive the path validation — and stays a recorded follow-up instead.

type DeltaApplier

type DeltaApplier interface {
	// ApplyDelta merges the changes captured in delta onto the current
	// workspace. A delta with no changes (a clean capture) is a no-op.
	// A conflicting delta returns an error and consumes nothing.
	ApplyDelta(ctx context.Context, delta trace.WorkspaceState) error
}

DeltaApplier is an optional Sandbox capability: applying a captured state's changes onto a workspace that has moved past the state's base, without resetting it. Sandbox.Apply is a full reset and is wrong for that case — it would roll the workspace back to the state's HEAD. Settlement's apply verb (plan 04 §2) needs the merge instead.

A delta state records its own base (the git backend carries the baseline tree it was measured against), so one argument is enough: the backend merges the delta onto whatever the workspace holds now. A conflict fails the call and must leave the workspace untouched.

Backends that cannot merge a delta return ErrUnsupported from the assertion's absence — callers detect the capability with a type assertion — a backend adds an optional surface without a kernel-wide interface change. Keeping this off the Sandbox interface means adding it is a backend decision, not a kernel-wide breaking change.

type DeltaBaseAnnotator

type DeltaBaseAnnotator interface {
	// AnnotateDeltaBase records the baseline's merge-base identity into
	// delta. baseline is the fork baseline the delta's changes are
	// measured against; delta is a fresh capture the caller is about to
	// seal. The key names are the backend's, opaque to the caller.
	AnnotateDeltaBase(ctx context.Context, delta *trace.WorkspaceState, baseline trace.WorkspaceState) error
}

DeltaBaseAnnotator is an optional Sandbox capability: the backend can record, on a freshly captured state, the merge base that state's changes are measured against, and pin the objects that base depends on against backend-side garbage collection. Settlement's Seal uses it at seal time, so a later ApplyDelta never needs to resolve a legacy identity (e.g. a minted stash commit) that garbage collection may already have reclaimed.

Backends whose deltas need no base simply do not implement it; callers detect it with a type assertion, the same pattern as DeltaApplier, so adding it is a backend decision, not a kernel-wide breaking change.

type ExecRequest

type ExecRequest struct {
	Command string
	Args    []string
	Cwd     string
	Env     map[string]string
	Timeout time.Duration
	Stdin   []byte

	// Confinement is the lowering of the caller's authority declaration. A nil
	// value asks the backend for its default (Permissive over the workspace for
	// the git backend). It carries the writable-root set, not raw roots, so the
	// authority layer (package confinement) is the only producer of roots.
	Confinement *confinement.ConfinementSpec
	// Placement selects where authority is enforced (paddock | advisory | auto).
	// An empty value asks the backend for its configured default.
	Placement containment.Placement
	// AuthorityMatch is the authority-surface digest the caller is enforcing
	// (optional). It is folded into the run's authority evidence when confined.
	AuthorityMatch string
}

ExecRequest describes one command execution inside a sandbox.

The shape mirrors the Daytona toolbox request (apps/daemon/pkg/toolbox/process/types.go) so a future HTTP backend is a straight mapping rather than an adapter.

type ExecResult

type ExecResult struct {
	ExitCode int
	Stdout   string
	Stderr   string
	Duration time.Duration
	// Denied reports that a confined run's failure reads as a syscall denial — the
	// write never reached disk. The runtime records a denied run as discarded,
	// Failed. The signal is heuristic (see containment.DeniedExit) and is only
	// ever set for confined runs.
	Denied bool
	// AuthorityEvidence is the paddock monitor's permission-plan digest for a confined
	// run (empty when unconfined). It cites which monitor enforced the run and is
	// the record the runtime persists so enforcement is auditable.
	AuthorityEvidence string
}

ExecResult is the outcome of one command execution.

type Sandbox

type Sandbox interface {
	// Backend returns the backend identifier ("git", "containerd", ...).
	Backend() string

	// Capabilities reports what this backend supports.
	Capabilities() SandboxCapabilities

	// Create provisions or validates the substrate. A materializer validates
	// that its target exists; an isolating backend allocates real resources.
	Create(ctx context.Context, spec SandboxSpec) error

	// Destroy releases resources this backend provisioned. It must never
	// destroy resources the backend did not create — a materializer pointed at
	// a user's repository must not delete it.
	Destroy(ctx context.Context) error

	// Capture records the current workspace state. Non-mutating.
	//
	// Contract: a capture of unchanged content at an unchanged timeline
	// position must be digest-stable — two captures of an identical
	// workspace must produce equal WorkspaceState digests, so a caller
	// can compare digests as content equality (settlement's select
	// precondition does). A workspace that only advanced its timeline —
	// a commit whose tree equals the prior content — is a *moved*
	// workspace by design: its capture digests differently, and callers
	// like settlement's select verb deliberately treat it as moved,
	// because their reset semantics would discard the commit; the
	// apply verb merges instead. The git backend satisfies this with
	// content-derived identities; a snapshot-backed backend whose
	// captures carry a per-capture sequence key does not, and must
	// record that as its own follow-up gap rather than silently
	// violating the contract.
	Capture(ctx context.Context) (trace.WorkspaceState, error)

	// Apply resets the workspace to a previously captured state. The git
	// backend's state is reusable; a snapshot-backed backend may instead
	// provision fresh resources and rebind its identity, making Apply
	// single-use per state. Callers must not assume reuse unless
	// Capabilities documents it.
	Apply(ctx context.Context, ws trace.WorkspaceState) error

	// Diff returns the unified diff and changed file paths between ws and the
	// current workspace. maxLines <= 0 means unbounded. Non-mutating.
	Diff(ctx context.Context, ws trace.WorkspaceState, maxLines int) (diff string, files []string, err error)

	// Exec runs a command in the sandbox and returns its result.
	//
	// The command always runs under a deadline: the request's Timeout when
	// one is given, or a backend default ceiling when it carries none, so a
	// caller passing context.Background() cannot hang indefinitely. The
	// git and landlock backends use a 10-minute default; an explicit
	// Timeout above the ceiling is honored as the caller's contract, not
	// clamped. A run the deadline kills surfaces as a context-deadline
	// error, never as a result with a negative exit code.
	Exec(ctx context.Context, req ExecRequest) (ExecResult, error)

	// ReadFile reads a file inside the sandbox workspace.
	ReadFile(ctx context.Context, path string) ([]byte, error)

	// WriteFile writes a file inside the sandbox workspace.
	WriteFile(ctx context.Context, path string, data []byte, perm fs.FileMode) error
}

Sandbox is the execution substrate for a scope. It owns a workspace and can provision it, snapshot it, restore it, diff it, and execute in it.

Backends need not implement every method: Capabilities reports which are available and unsupported methods return ErrUnsupported. This lets the git backend, which is a materializer rather than an isolation boundary, satisfy the interface without pretending to provide execution or isolation.

Every method takes a context so remote backends can honor cancellation and deadlines. Local backends should still impose their own ceiling (the git backend bounds each subprocess with gitTimeout) so a caller passing context.Background() cannot hang indefinitely.

Non-mutating contract: Capture and Diff must leave the caller's workspace metadata unchanged on return. For git that means the index must be left as it was found.

func OpenSandbox

func OpenSandbox(backend string, cfg any) (Sandbox, error)

OpenSandbox constructs the named backend's Sandbox from the backend's own configuration type. The sandbox is not provisioned — call Create as the lifecycle contract requires.

type SandboxCapabilities

type SandboxCapabilities struct {
	// Lifecycle reports whether Create and Destroy manage real resources.
	// A backend that only validates or materializes reports false.
	Lifecycle bool
	// Exec reports whether Exec is implemented.
	Exec bool
	// FileIO reports whether ReadFile and WriteFile are implemented.
	FileIO bool
	// Diff reports whether Diff is implemented.
	Diff bool
	// Isolated reports whether the workspace is isolated from the host
	// filesystem. A false value means the backend mutates the host tree
	// in place.
	Isolated bool
	// Containment is the witness-level containment classification for the
	// substrate, stamped into trace witnesses and retained contexts.
	Containment trace.Containment
}

SandboxCapabilities declares what a backend supports and how its workspace is contained. Callers use it to decide whether an optional operation is available before invoking it.

type SandboxFactory

type SandboxFactory func(cfg any) (Sandbox, error)

SandboxFactory builds a Sandbox from backend-defined configuration for config-driven backend selection: a host resolves a configured backend name through OpenSandbox instead of importing each backend's constructor.

cfg is opaque to the kernel — each backend documents the concrete type it accepts (the built-in git backend takes GitSandboxConfig) and rejects anything else loudly, so a configuration mismatch is a startup error, not a silent default.

The returned Sandbox is NOT provisioned: Create remains a separate, explicit lifecycle step, exactly as it is for direct constructor use.

type SandboxSpec

type SandboxSpec struct {
	// Workdir is the workspace path for backends that mount or check out into
	// a caller-chosen directory. Ignored by backends that infer their own.
	Workdir string
	// Env is the environment for commands run during Create (for example a
	// bootstrap step). It is not the agent's execution environment.
	Env map[string]string
	// Timeout bounds the Create operation. Zero means the backend default.
	Timeout time.Duration
}

SandboxSpec carries per-call runtime options for Create. Backend-specific configuration (repository path, base image, credentials) belongs on the backend constructor, not here.

type UnknownSandboxBackendError

type UnknownSandboxBackendError struct {
	Backend   string
	Available []string
}

UnknownSandboxBackendError names the backend that was asked for and the backends that are actually registered, so a config typo fails with the valid options instead of a bare "not found".

func (*UnknownSandboxBackendError) Error

func (*UnknownSandboxBackendError) Is

func (e *UnknownSandboxBackendError) Is(target error) bool

Directories

Path Synopsis
Package confinement is the authority-enforcement seam: it owns the spec vocabulary (ConfinementSpec, NetworkPolicy, the Net* modes and their lowerings) and lowers an authority declaration — a may= profile or a set of per-binding grants — to such a spec.
Package confinement is the authority-enforcement seam: it owns the spec vocabulary (ConfinementSpec, NetworkPolicy, the Net* modes and their lowerings) and lowers an authority declaration — a may= profile or a set of per-binding grants — to such a spec.
Package containment is the syscall-deny paddock contract: the seam that makes a confinement.ConfinementSpec real at the OS boundary, plus the placement tiers (Placement, ResolvePlacement).
Package containment is the syscall-deny paddock contract: the seam that makes a confinement.ConfinementSpec real at the OS boundary, plus the placement tiers (Placement, ResolvePlacement).
croft module
Package egress is the network-egress mediation axis: a host predicate the syscall jail cannot evaluate (the jail is host-blind) plus a loopback HTTP-CONNECT proxy that enforces it.
Package egress is the network-egress mediation axis: a host predicate the syscall jail cannot evaluate (the jail is host-blind) plus a loopback HTTP-CONNECT proxy that enforces it.
Package git is the core module's git sandbox backend: the in-place materializer over the caller's repository and the detached-worktree isolated mode, both addressable through the sandbox package's registry as "git" (the backend self-registers on import).
Package git is the core module's git sandbox backend: the in-place materializer over the caller's repository and the detached-worktree isolated mode, both addressable through the sandbox package's registry as "git" (the backend self-registers on import).
landlock module
seatbelt module
winacl module

Jump to

Keyboard shortcuts

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