driver

package
v0.0.0-...-bdc9112 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: AGPL-3.0 Imports: 41 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RuntimeDriverBoxlite      = "boxlite"
	RuntimeDriverDocker       = "docker"
	RuntimeDriverMicrosandbox = "microsandbox"
	RuntimeDriverK8s          = "k8s"
)
View Source
const (
	MetricUnitPercent = "percent"
	MetricUnitBytes   = "bytes"
	MetricUnitSeconds = "seconds"
)
View Source
const (
	MetricStatusOK          = "ok"
	MetricStatusUnknown     = "unknown"
	MetricStatusUnavailable = "unavailable"
)
View Source
const DirectoryOnlyGuestSandboxPath = directoryOnlyGuestSandboxPath

Variables

View Source
var (
	// ErrGuestRuntimeNotReady means the guest runtime has not installed its
	// signal handler and published its PID yet.
	ErrGuestRuntimeNotReady = errors.New("guest runtime is not ready for signals")
	// ErrGuestRuntimeGone means the ready file no longer identifies the
	// tracked agent-compose-runtime process.
	ErrGuestRuntimeGone = errors.New("guest runtime is no longer running")
)
View Source
var ErrExecTerminationUnconfirmed = errors.New("guest execution termination unconfirmed")

ErrExecTerminationUnconfirmed means a runtime driver returned without being able to prove that the guest execution it started has stopped.

View Source
var ErrRuntimeDriverNotCompiled = errors.New("runtime driver not compiled")

ErrRuntimeDriverNotCompiled identifies a runtime driver that the product recognizes but the current binary was not built to support.

View Source
var ErrRuntimeInteractionUnsupported = errors.New("runtime interaction unsupported")

Functions

func CleanupBoxliteVolumeBridgeMounts

func CleanupBoxliteVolumeBridgeMounts(sessionDir string) error

CleanupBoxliteVolumeBridgeMounts releases host-side bridge mounts under a session directory. It is safe to call for sessions that do not use BoxLite or do not have volume bridges.

func CompiledRuntimeDrivers

func CompiledRuntimeDrivers() []string

CompiledRuntimeDrivers returns the runtime drivers included in this binary. The result is ordered and may be modified by the caller.

func DefaultGuestImageForDriver

func DefaultGuestImageForDriver(config *appconfig.Config, driver string) string

func EnsureDockerImage

func EnsureDockerImage(ctx context.Context, imageRef string) (string, error)

func GuestRuntimeControlEnv

func GuestRuntimeControlEnv(env map[string]string, executionID string) map[string]string

GuestRuntimeControlEnv copies env and installs the private host/guest runtime identity used by graceful-stop control operations.

func IsRuntimeDriverCompiled

func IsRuntimeDriverCompiled(value string) bool

IsRuntimeDriverCompiled reports whether the normalized runtime driver is included in this binary.

func JupyterConnectAddress

func JupyterConnectAddress(proxyState ProxyState) string

func JupyterConnectTarget

func JupyterConnectTarget(proxyState ProxyState) (host string, port int)

func LLMProviderKeyName

func LLMProviderKeyName(name string) bool

LLMProviderKeyName reports whether name is long-lived LLM provider configuration that must never be passed through to a guest runtime. It is the canonical denylist shared by driver env assembly and the facade layer.

func NewRuntimeCacheSources

func NewRuntimeCacheSources(config *appconfig.Config) []cache.Source

func NewRuntimeInteractionUnsupportedError

func NewRuntimeInteractionUnsupportedError(driver string, spec RuntimeStartSpec, capability RuntimeInteractionCapability, reason string) error

func RemoveDockerManagedResource

func RemoveDockerManagedResource(ctx context.Context, config *appconfig.Config, resource ManagedRuntimeResource) error

func ResolveRuntimeDriver

func ResolveRuntimeDriver(value string) string

func ResolveSandboxGuestImage

func ResolveSandboxGuestImage(values ...string) string

func ResolveSandboxRuntimeDriver

func ResolveSandboxRuntimeDriver(value, fallback string) (string, error)

func RuntimeDriverSupportsStoppedRuntimeRetention

func RuntimeDriverSupportsStoppedRuntimeRetention(driver string) bool

RuntimeDriverSupportsStoppedRuntimeRetention reports whether a driver can stop a sandbox while preserving the same private writable runtime for a later resume. Kubernetes Pods have no stopped-but-retained lifecycle state: stopping a Pod deletes it, and resume creates a new Pod from the image.

func RuntimeHomeForDriver

func RuntimeHomeForDriver(config *appconfig.Config, driver string) string

func RuntimeRefPrefix

func RuntimeRefPrefix(driver string) string

RuntimeRefPrefix returns the prefix sandboxstore uses to precompute a new sandbox's RuntimeRef (and, for every driver, the resulting container/Pod name each driver's own naming fallback would otherwise compute) before the driver itself has run. The k8s driver's Pod name is deliberately prefixed "agent-compose-sandbox-" rather than bare "agent-compose-" so it reads distinctly from the daemon's own Deployment-managed Pod name in a plain `kubectl get pods` (see k8sRuntime.podName) - this must return the same prefix that fallback would, or the precomputed RuntimeRef silently wins over it via firstNonEmpty and the k8s-specific naming never takes effect.

func SandboxStopContextTimeout

func SandboxStopContextTimeout(driver string, stopTimeout time.Duration) time.Duration

func ValidateCompiledRuntimeDriver

func ValidateCompiledRuntimeDriver(value string) error

ValidateCompiledRuntimeDriver validates both the runtime driver name and whether support for that driver is included in this binary.

func ValidateRuntimeDriver

func ValidateRuntimeDriver(value string) error

func WaitForJupyterProxy

func WaitForJupyterProxy(ctx context.Context, proxyState ProxyState) error

Types

type ExecChunk

type ExecChunk struct {
	// Text is valid UTF-8. Runtime byte streams must buffer incomplete rune
	// suffixes and replace irrecoverably invalid input before emitting a chunk.
	Text   string
	Stream StdioStream
}

type ExecResult

type ExecResult struct {
	ExitCode int
	Stdout   string
	Stderr   string
	Output   string
	Success  bool
}

type ExecSpec

type ExecSpec struct {
	Command string            `json:"command"`
	Args    []string          `json:"args,omitempty"`
	Env     map[string]string `json:"env,omitempty"`
	Cwd     string            `json:"cwd,omitempty"`
}

func ExecSpecFromRuntimeStartSpec

func ExecSpecFromRuntimeStartSpec(spec RuntimeStartSpec) ExecSpec

type ExecStreamInteractionRequest

type ExecStreamInteractionRequest struct {
	Session *Sandbox
	VMState VMState
	Spec    RuntimeStartSpec
}

ExecStreamInteractionRequest describes the sandbox and command to stream-exec.

type ExecStreamWriter

type ExecStreamWriter func(ExecChunk)

type GuestDirectoryPublication

type GuestDirectoryPublication struct {
	HostSource       string
	GuestDestination string
	ManagedMarker    string
}

GuestDirectoryPublication describes a private guest directory publication. ManagedMarker identifies a legacy directory that this caller owns.

type GuestSymlinkProjection

type GuestSymlinkProjection struct {
	GuestPath      string
	RelativeTarget string
	ManagedMarkers []string
}

GuestSymlinkProjection describes an alias inside the private guest home. ManagedMarkers name caller-owned legacy formats; unrelated paths are refused.

type ManagedRuntimeResource

type ManagedRuntimeResource struct {
	Driver         string
	RuntimeID      string
	SandboxID      string
	UpdatedAt      time.Time
	OwnershipValid bool
	Removable      bool
	BlockedReasons []string
	OwnedPaths     []string
}

func ListDockerManagedResources

func ListDockerManagedResources(ctx context.Context, config *appconfig.Config) ([]ManagedRuntimeResource, error)

func ListMicrosandboxManagedResources

func ListMicrosandboxManagedResources(context.Context, *appconfig.Config) ([]ManagedRuntimeResource, []string, error)

type MetricValue

type MetricValue struct {
	Value   *float64
	Unit    string
	Status  string
	Message string
}

type ProxyState

type ProxyState struct {
	ProxyPath  string `json:"proxy_path"`
	GuestHost  string `json:"guest_host"`
	HostPort   int    `json:"host_port"`
	GuestPort  int    `json:"guest_port"`
	JupyterURL string `json:"jupyter_url,omitempty"`
	Token      string `json:"token,omitempty"`
	Enabled    bool   `json:"enabled,omitempty"`
	Exposed    bool   `json:"exposed,omitempty"`
}

type ProxyStateReader

type ProxyStateReader func(sandboxID string) (ProxyState, error)

ProxyStateReader fetches a sandbox's persisted ProxyState directly from the store. The k8s driver needs this because, unlike docker/microsandbox, it can't trust the proxyState an individual EnsureSandbox call happens to receive: EnsureSandbox is invoked from several call sites (guest file pushes, exec-ensure) that don't carry real jupyter config, and whichever call creates the Pod first fixes its Command forever - so the decision of whether to launch jupyter has to come from durable state, not an ad-hoc parameter. See k8sRuntime.resolveProxyState.

type RuntimeAgentEvent

type RuntimeAgentEvent struct {
	Type     string            `json:"type"`
	Message  string            `json:"message,omitempty"`
	Payload  []byte            `json:"payload,omitempty"`
	Metadata map[string]string `json:"metadata,omitempty"`
}

type RuntimeAgentSpec

type RuntimeAgentSpec struct {
	Provider  string            `json:"provider,omitempty"`
	Model     string            `json:"model,omitempty"`
	Prompt    string            `json:"prompt,omitempty"`
	SessionID string            `json:"session_id,omitempty"`
	Metadata  map[string]string `json:"metadata,omitempty"`
}

type RuntimeCommandSpec

type RuntimeCommandSpec struct {
	Command string            `json:"command"`
	Args    []string          `json:"args,omitempty"`
	Env     map[string]string `json:"env,omitempty"`
	Cwd     string            `json:"cwd,omitempty"`
}

type RuntimeDriverNotCompiledError

type RuntimeDriverNotCompiledError struct {
	Driver          string
	GOOS            string
	GOARCH          string
	CompiledDrivers []string
}

RuntimeDriverNotCompiledError describes a runtime driver missing from the current binary's build capabilities.

func (*RuntimeDriverNotCompiledError) Error

func (*RuntimeDriverNotCompiledError) Unwrap

type RuntimeError

type RuntimeError struct {
	Code    string `json:"code,omitempty"`
	Message string `json:"message"`
}

type RuntimeInputFrame

type RuntimeInputFrame struct {
	Type    RuntimeInputFrameType `json:"type"`
	Data    []byte                `json:"data,omitempty"`
	Rows    uint32                `json:"rows,omitempty"`
	Cols    uint32                `json:"cols,omitempty"`
	Signal  RuntimeSignal         `json:"signal,omitempty"`
	Message string                `json:"message,omitempty"`
}

type RuntimeInputFrameType

type RuntimeInputFrameType string
const (
	RuntimeInputStdin        RuntimeInputFrameType = "stdin"
	RuntimeInputStdinEOF     RuntimeInputFrameType = "stdin_eof"
	RuntimeInputResize       RuntimeInputFrameType = "resize"
	RuntimeInputSignal       RuntimeInputFrameType = "signal"
	RuntimeInputHumanMessage RuntimeInputFrameType = "human_message"
	RuntimeInputCancel       RuntimeInputFrameType = "cancel"
)

type RuntimeInteraction

type RuntimeInteraction interface {
	Send(RuntimeInputFrame) error
	CloseSend() error
	Recv() (RuntimeOutputFrame, error)
	Wait() (RuntimeResult, error)
}

func GuardRuntimeInteractionInput

func GuardRuntimeInteractionInput(interaction RuntimeInteraction) RuntimeInteraction

GuardRuntimeInteractionInput serializes Send and CloseSend so an input pump can finish concurrently with the output loop without closing stdin twice or sending after it has been closed.

func UnsupportedRuntimeInteraction

func UnsupportedRuntimeInteraction(driver string, caps RuntimeInteractionCapabilities, spec RuntimeStartSpec) (RuntimeInteraction, error)

type RuntimeInteractionCapabilities

type RuntimeInteractionCapabilities struct {
	NativeExec    bool `json:"native_exec"`
	WrapperStream bool `json:"wrapper_stream"`
	Stdin         bool `json:"stdin"`
	StdinEOF      bool `json:"stdin_eof"`
	TTY           bool `json:"tty"`
	Resize        bool `json:"resize"`
	Signal        bool `json:"signal"`
	Artifacts     bool `json:"artifacts"`
	AgentTurns    bool `json:"agent_turns"`
}

func (RuntimeInteractionCapabilities) ValidateStartSpec

func (c RuntimeInteractionCapabilities) ValidateStartSpec(driver string, spec RuntimeStartSpec) error

type RuntimeInteractionCapability

type RuntimeInteractionCapability string
const (
	RuntimeCapabilityNativeExec    RuntimeInteractionCapability = "native_exec"
	RuntimeCapabilityWrapperStream RuntimeInteractionCapability = "wrapper_stream"
	RuntimeCapabilityStdin         RuntimeInteractionCapability = "stdin"
	RuntimeCapabilityStdinEOF      RuntimeInteractionCapability = "stdin_eof"
	RuntimeCapabilityTTY           RuntimeInteractionCapability = "tty"
	RuntimeCapabilityResize        RuntimeInteractionCapability = "resize"
	RuntimeCapabilitySignal        RuntimeInteractionCapability = "signal"
	RuntimeCapabilityArtifacts     RuntimeInteractionCapability = "artifacts"
	RuntimeCapabilityAgentTurns    RuntimeInteractionCapability = "agent_turns"
)

type RuntimeInteractionUnsupportedError

type RuntimeInteractionUnsupportedError struct {
	Driver     string
	Operation  RuntimeOperationKind
	Capability RuntimeInteractionCapability
	Reason     string
}

func (*RuntimeInteractionUnsupportedError) Error

func (*RuntimeInteractionUnsupportedError) Unwrap

type RuntimeInteractor

type RuntimeInteractor interface {
	InteractionCapabilities() RuntimeInteractionCapabilities
	OpenInteraction(context.Context, *Sandbox, VMState, RuntimeStartSpec) (RuntimeInteraction, error)
}

type RuntimeMount

type RuntimeMount struct {
	HostPath  string `json:"hostPath"`
	GuestPath string `json:"guestPath"`
	Type      string `json:"type"`
	ReadOnly  bool   `json:"readOnly"`
}

type RuntimeMountManifest

type RuntimeMountManifest struct {
	Version int            `json:"version"`
	Driver  string         `json:"driver"`
	Mounts  []RuntimeMount `json:"mounts"`
}

func BuildRuntimeMountManifest

func BuildRuntimeMountManifest(config *appconfig.Config, session *Sandbox, driver string) (RuntimeMountManifest, error)

func LoadDirectoryRuntimeMountManifest

func LoadDirectoryRuntimeMountManifest(session *Sandbox, expectedDriver string) (RuntimeMountManifest, error)

func LoadRuntimeMountManifest

func LoadRuntimeMountManifest(session *Sandbox, expectedDriver string) (RuntimeMountManifest, error)

func PrepareRuntimeMountManifest

func PrepareRuntimeMountManifest(config *appconfig.Config, session *Sandbox, driver string) (RuntimeMountManifest, error)

type RuntimeOperationKind

type RuntimeOperationKind string
const (
	RuntimeOperationCommand RuntimeOperationKind = "command"
	RuntimeOperationAgent   RuntimeOperationKind = "agent"
)

type RuntimeOutputFrame

type RuntimeOutputFrame struct {
	Type RuntimeOutputFrameType `json:"type"`
	// Data in stdout and stderr frames is valid UTF-8 text. Runtime byte
	// streams must complete or replace invalid rune fragments before emitting.
	Data      []byte             `json:"data,omitempty"`
	Event     *RuntimeAgentEvent `json:"event,omitempty"`
	Result    *RuntimeResult     `json:"result,omitempty"`
	Error     *RuntimeError      `json:"error,omitempty"`
	StartedAt time.Time          `json:"started_at,omitempty"`
}

type RuntimeOutputFrameType

type RuntimeOutputFrameType string
const (
	RuntimeOutputStarted            RuntimeOutputFrameType = "started"
	RuntimeOutputStdout             RuntimeOutputFrameType = "stdout"
	RuntimeOutputStderr             RuntimeOutputFrameType = "stderr"
	RuntimeOutputAgentEvent         RuntimeOutputFrameType = "agent_event"
	RuntimeOutputAgentTurnCompleted RuntimeOutputFrameType = "agent_turn_completed"
	RuntimeOutputResult             RuntimeOutputFrameType = "result"
	RuntimeOutputError              RuntimeOutputFrameType = "error"
)

type RuntimeResult

type RuntimeResult struct {
	OperationID string            `json:"operation_id,omitempty"`
	ExitCode    int               `json:"exit_code"`
	Success     bool              `json:"success"`
	Error       string            `json:"error,omitempty"`
	StartedAt   time.Time         `json:"started_at,omitempty"`
	CompletedAt time.Time         `json:"completed_at,omitempty"`
	Artifacts   map[string]string `json:"artifacts,omitempty"`
}

type RuntimeSignal

type RuntimeSignal string
const (
	RuntimeSignalInterrupt RuntimeSignal = "interrupt"
	RuntimeSignalTerminate RuntimeSignal = "terminate"
	RuntimeSignalKill      RuntimeSignal = "kill"
)

type RuntimeStartSpec

type RuntimeStartSpec struct {
	OperationID string               `json:"operation_id,omitempty"`
	Kind        RuntimeOperationKind `json:"kind"`
	Origin      string               `json:"origin,omitempty"`
	Command     *RuntimeCommandSpec  `json:"command,omitempty"`
	Agent       *RuntimeAgentSpec    `json:"agent,omitempty"`
	Cwd         string               `json:"cwd,omitempty"`
	Env         map[string]string    `json:"env,omitempty"`
	AttachStdin bool                 `json:"attach_stdin,omitempty"`
	TTY         bool                 `json:"tty,omitempty"`
	Rows        uint32               `json:"rows,omitempty"`
	Cols        uint32               `json:"cols,omitempty"`
	TimeoutMs   int64                `json:"timeout_ms,omitempty"`
	ArtifactDir string               `json:"artifact_dir,omitempty"`
}

type Sandbox

type Sandbox struct {
	Summary         SandboxSummary       `json:"summary"`
	Workspace       *SandboxWorkspace    `json:"workspace,omitempty"`
	EnvItems        []SandboxEnvVar      `json:"env_items,omitempty"`
	VolumeMounts    []SandboxVolumeMount `json:"volume_mounts,omitempty"`
	RuntimeEnvItems []SandboxEnvVar      `json:"-"`
}

type SandboxEnvVar

type SandboxEnvVar struct {
	Name   string `json:"name"`
	Value  string `json:"value,omitempty"`
	Secret bool   `json:"secret,omitempty"`
}

type SandboxRuntime

func NewBoxliteRuntime

func NewBoxliteRuntime(config *appconfig.Config) (SandboxRuntime, error)

func NewDockerRuntime

func NewDockerRuntime(config *appconfig.Config) (SandboxRuntime, error)

func NewK8sRuntime

func NewK8sRuntime(config *appconfig.Config, proxyStateReader ProxyStateReader) (SandboxRuntime, error)

func NewMicrosandboxRuntime

func NewMicrosandboxRuntime(config *appconfig.Config) (SandboxRuntime, error)

type SandboxStartTarget

type SandboxStartTarget struct {
	Driver  string
	Session *Sandbox
	VMState VMState
}

SandboxStartTarget identifies the sandbox and runtime driver to prepare for start.

type SandboxStats

type SandboxStats struct {
	SandboxID        string
	Driver           string
	SampledAt        time.Time
	CPUPercent       MetricValue
	MemoryUsageBytes MetricValue
	MemoryLimitBytes MetricValue
	MemoryPercent    MetricValue
	NetworkRxBytes   MetricValue
	NetworkTxBytes   MetricValue
	BlockReadBytes   MetricValue
	BlockWriteBytes  MetricValue
	UptimeSeconds    MetricValue
}

type SandboxSummary

type SandboxSummary struct {
	ID            string    `json:"id"`
	Driver        string    `json:"driver"`
	GuestImage    string    `json:"guest_image,omitempty"`
	PullPolicy    string    `json:"pull_policy,omitempty"`
	RuntimeRef    string    `json:"runtime_ref,omitempty"`
	WorkspacePath string    `json:"workspace_path"`
	CreatedAt     time.Time `json:"created_at"`
	UpdatedAt     time.Time `json:"updated_at"`
}

type SandboxVMInfo

type SandboxVMInfo struct {
	BoxID      string
	JupyterURL string
	ProxyState *ProxyState
}

type SandboxVolumeMount

type SandboxVolumeMount struct {
	ID       string `json:"id,omitempty"`
	Type     string `json:"type"`
	Source   string `json:"source"`
	Target   string `json:"target"`
	ReadOnly bool   `json:"read_only,omitempty"`
	VolumeID string `json:"volume_id,omitempty"`
	Driver   string `json:"driver,omitempty"`
	HostPath string `json:"host_path"`
}

type SandboxWorkspace

type SandboxWorkspace struct {
	Type       string `json:"type"`
	ConfigJSON string `json:"config_json"`
}

SandboxWorkspace carries the persisted delivery contract into the runtime boundary.

type StdioStream

type StdioStream string
const (
	StdioStdout StdioStream = "stdout"
	StdioStderr StdioStream = "stderr"
)

func NormalizeStdioStream

func NormalizeStdioStream(stream StdioStream) StdioStream

type VMState

type VMState struct {
	Driver           string    `json:"driver"`
	Mode             string    `json:"mode,omitempty"`
	BoxName          string    `json:"box_name,omitempty"`
	BoxID            string    `json:"box_id,omitempty"`
	Image            string    `json:"image,omitempty"`
	Registry         string    `json:"registry,omitempty"`
	RuntimeHome      string    `json:"runtime_home,omitempty"`
	StartedAt        time.Time `json:"started_at,omitempty"`
	StartAttemptedAt time.Time `json:"start_attempted_at,omitempty"`
	StoppedAt        time.Time `json:"stopped_at,omitempty"`
	LastError        string    `json:"last_error,omitempty"`
	BootstrapRef     string    `json:"bootstrap_ref,omitempty"`
	// K8sContext and K8sNamespace override which cluster/namespace the k8s
	// driver targets for this sandbox. Empty means "use the daemon's
	// K8S_KUBECONFIG current-context / K8S_NAMESPACE default" (see
	// k8sRuntime.client and k8sRuntime.namespaceFor). Other drivers ignore
	// these fields.
	K8sContext   string `json:"k8s_context,omitempty"`
	K8sNamespace string `json:"k8s_namespace,omitempty"`
}

func PrepareSandboxStart

func PrepareSandboxStart(ctx context.Context, config *appconfig.Config, target SandboxStartTarget) (VMState, error)

Jump to

Keyboard shortcuts

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