Documentation
¶
Overview ¶
Package runtime provides interfaces and types for managing AI agent workspace runtimes. A runtime is an execution environment (e.g., container, process) that hosts a workspace instance.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrRuntimeNotFound is returned when a requested runtime type is not registered. ErrRuntimeNotFound = errors.New("runtime not found") // ErrInstanceNotFound is returned when a requested runtime instance does not exist. ErrInstanceNotFound = errors.New("runtime instance not found") // (e.g., podman binary not found, docker daemon not running). ErrRuntimeUnavailable = errors.New("runtime unavailable") // ErrInvalidParams is returned when create parameters are invalid or incomplete. ErrInvalidParams = errors.New("invalid runtime parameters") )
Functions ¶
func ValidateState ¶
func ValidateState(state api.WorkspaceState) error
ValidateState validates that a runtime state is one of the valid WorkspaceState values. Valid states are: "running", "stopped", "error", "unknown". Returns an error if the state is not valid.
Types ¶
type AgentLister ¶
type AgentLister interface {
// ListAgents returns the names of all agents supported by this runtime.
// Returns an empty slice if no agents are configured.
ListAgents() ([]string, error)
}
AgentLister is an optional interface for runtimes that can report which agents they support. Runtimes implementing this interface enable discovery of available agents without requiring direct knowledge of the runtime's internal configuration.
Example implementation:
type myRuntime struct {
configDir string
}
func (r *myRuntime) ListAgents() ([]string, error) {
// Scan configuration directory for agent definitions
return []string{"claude", "goose"}, nil
}
type ConfigTransformer ¶ added in v0.9.0
type ConfigTransformer interface {
TransformConfig(config *workspace.WorkspaceConfiguration) error
}
ConfigTransformer is an optional interface for runtimes that need to transform workspace configuration before it is processed by agents. For example, a container runtime may rewrite localhost URLs in MCP command args to make host services reachable from inside the container.
TransformConfig is called after configuration merging but before agent settings are generated (e.g., before SetMCPServers bakes MCP config into agent setting files). Implementations should mutate the config in place.
Example implementation:
func (r *myRuntime) TransformConfig(config *workspace.WorkspaceConfiguration) error {
if config.Mcp != nil {
rewriteLocalhostURLs(config.Mcp)
}
return nil
}
type CreateParams ¶
type CreateParams struct {
// Name is the human-readable name for the instance.
Name string
// SourcePath is the absolute path to the workspace source directory.
SourcePath string
// WorkspaceConfig is the workspace configuration (optional, can be nil if no configuration exists).
WorkspaceConfig *workspace.WorkspaceConfiguration
// Agent is the agent name for loading agent-specific configuration (required, cannot be empty).
Agent string
// AgentSettings contains the agent settings files to embed into the agent user's
// home directory in the workspace image. Keys are relative file paths using
// forward slashes (e.g., ".claude/settings.json"), values are file contents.
// This map can be nil or empty if no default settings are configured.
AgentSettings map[string][]byte
// OnecliSecrets contains pre-mapped OneCLI secret definitions to provision
// when the workspace is first started. These are created by the manager from
// workspace configuration secrets. Can be nil or empty.
OnecliSecrets []onecli.CreateSecretInput
// SecretEnvVars maps environment variable names to placeholder values.
// These are derived from secret service definitions (e.g. GH_TOKEN, GITHUB_TOKEN
// for the "github" secret type) and injected into the workspace container so
// that CLI tools detect a configured credential. Real auth goes through OneCLI proxy.
SecretEnvVars map[string]string
// WorkspaceConfigDir is the directory containing the workspace configuration file.
// Used to resolve relative paths for local devcontainer features (e.g. "./my-feature").
// Can be empty if no workspace configuration exists.
WorkspaceConfigDir string
// ProjectID is the project identifier used to load per-project workspace
// configuration (e.g. network policy) during subsequent Start() calls.
ProjectID string
// RuntimeOptions contains runtime-specific flag values collected from
// the CLI. Keys are flag names (matching FlagDef.Name), values are the
// user-provided strings. This map is nil when no runtime flags were set.
RuntimeOptions map[string]string
}
CreateParams contains parameters for creating a new runtime instance.
type Dashboard ¶ added in v0.6.0
type Dashboard interface {
// GetURL returns the dashboard URL for the given runtime instance ID.
// The instance is guaranteed to be running when this method is called.
// Returns an error if the dashboard URL cannot be determined.
GetURL(ctx context.Context, instanceID string) (string, error)
}
Dashboard is an optional interface for runtimes that provide a web dashboard. Runtimes implementing this interface expose a URL for accessing the workspace dashboard.
Callers (e.g. the instances manager) are responsible for verifying that the instance is in the running state before invoking GetURL. Implementations may assume the instance is running and focus solely on resolving the URL.
Example implementation:
func (r *myRuntime) GetURL(ctx context.Context, instanceID string) (string, error) {
port, err := r.readStoredPort(instanceID)
if err != nil {
return "", err
}
return fmt.Sprintf("http://localhost:%d", port), nil
}
type FlagDef ¶ added in v0.8.0
type FlagDef struct {
// Name is the flag name (e.g., "openshell-driver").
Name string
// Usage is the help text shown for the flag.
Usage string
// Completions is an optional list of static values for shell completion.
Completions []string
}
FlagDef describes a CLI flag that a runtime wants to expose on the init command.
type FlagProvider ¶ added in v0.8.0
type FlagProvider interface {
Flags() []FlagDef
}
FlagProvider is an optional interface for runtimes that need additional CLI flags on the init command. Runtimes implementing this interface declare their flags via Flags(), and the command layer registers them on the cobra command.
Flag values are collected into a map[string]string and passed through AddOptions.RuntimeOptions and CreateParams.RuntimeOptions so that the runtime's Create method can access them without the command layer knowing what they mean.
type Registry ¶
type Registry interface {
// Register adds a runtime to the registry.
// Returns an error if a runtime with the same type is already registered.
Register(runtime Runtime) error
// Get retrieves a runtime by type.
// Returns ErrRuntimeNotFound if the runtime type is not registered.
Get(runtimeType string) (Runtime, error)
// List returns all registered runtime types.
List() []string
}
Registry manages available runtime implementations.
func NewRegistry ¶
NewRegistry creates a new runtime registry with the specified storage directory. The storage directory is used to create runtime-specific subdirectories at REGISTRY_STORAGE/runtimeType.
type Runtime ¶
type Runtime interface {
// Type returns the runtime type identifier (e.g., "podman", "docker", "process", "fake").
Type() string
// WorkspaceSourcesPath returns the path where sources will be mounted inside the workspace.
// This is a constant for each runtime type and doesn't require an instance to exist.
WorkspaceSourcesPath() string
// Create creates a new runtime instance without starting it.
// Returns RuntimeInfo with the assigned instance ID and initial state.
Create(ctx context.Context, params CreateParams) (RuntimeInfo, error)
// Start starts a previously created runtime instance.
// Returns updated RuntimeInfo with running state.
Start(ctx context.Context, id string) (RuntimeInfo, error)
// Stop stops a running runtime instance without removing it.
// The instance can be started again later.
Stop(ctx context.Context, id string) error
// Remove removes a runtime instance and cleans up all associated resources.
// The instance must be stopped before removal.
Remove(ctx context.Context, id string) error
// Info retrieves current information about a runtime instance.
Info(ctx context.Context, id string) (RuntimeInfo, error)
}
Runtime manages the lifecycle of workspace instances in a specific execution environment. Implementations might use containers (podman, docker), processes, or other isolation mechanisms.
type RuntimeInfo ¶
type RuntimeInfo struct {
// ID is the runtime-assigned instance identifier.
ID string
// State is the current runtime state.
State api.WorkspaceState
// Info contains runtime-specific metadata as key-value pairs.
// Examples: container_id, pid, created_at, network addresses.
Info map[string]string
}
RuntimeInfo contains information about a runtime instance.
type SecretServiceRegistryAware ¶ added in v0.6.0
type SecretServiceRegistryAware interface {
SetSecretServiceRegistry(secretservice.Registry)
}
SecretServiceRegistryAware is an optional interface for runtimes that need the secret service registry to resolve host patterns for networking decisions. Runtimes implementing this interface receive the registry via SetSecretServiceRegistry during registration, enabling them to look up host patterns for secret-derived hosts.
type StorageAware ¶
type StorageAware interface {
// Initialize is called during registration with the runtime's private storage directory.
// The directory is created before this method is called and is guaranteed to exist.
// The path will be: REGISTRY_STORAGE/runtimeType
//
// Runtimes should store the directory path and use it for persisting private data.
// This method is called exactly once during registration, before the runtime is available for use.
Initialize(storageDir string) error
}
StorageAware is an optional interface that runtimes can implement to receive a dedicated storage directory during registration.
When a runtime implements this interface, the Registry will:
- Create a directory at REGISTRY_STORAGE/runtimeType
- Call Initialize with the absolute path to this directory
- The runtime can use this directory to persist private data
Example implementation:
type myRuntime struct {
storageDir string
}
func (r *myRuntime) Initialize(storageDir string) error {
r.storageDir = storageDir
// Optional: create subdirectories, load state, etc.
return os.MkdirAll(filepath.Join(storageDir, "instances"), 0755)
}
func (r *myRuntime) Create(ctx context.Context, params CreateParams) (RuntimeInfo, error) {
// Use r.storageDir to persist instance data
instanceFile := filepath.Join(r.storageDir, "instances", id+".json")
return os.WriteFile(instanceFile, data, 0644)
}
type Terminal ¶
type Terminal interface {
// Terminal starts an interactive terminal session inside a running instance.
// The command is executed with stdin/stdout/stderr connected directly to the user's terminal.
// Returns an error if the instance is not running or command execution fails.
//
// Parameters:
// - ctx: Context for cancellation and timeout
// - instanceID: The runtime instance identifier
// - agent: The agent name for loading agent-specific configuration
// - command: The command to execute (e.g., ["bash"], ["claude-code", "--debug"]).
// If empty, the runtime will use the agent's configured terminal command.
Terminal(ctx context.Context, instanceID string, agent string, command []string) error
}
Terminal is an optional interface for runtimes that support interactive terminal sessions. Runtimes implementing this interface enable the terminal command for connecting to running instances.
When a runtime implements this interface, users can:
- Connect to running instances with an interactive terminal
- Execute commands directly inside the instance environment
- Interact with agents or shells running in the instance
Example implementation:
type myRuntime struct {
// ... other fields
}
func (r *myRuntime) Terminal(ctx context.Context, instanceID string, agent string, command []string) error {
// Execute command interactively (stdin/stdout/stderr connected)
return r.exec.RunInteractive(ctx, "exec", "-it", instanceID, command...)
}
Directories
¶
| Path | Synopsis |
|---|---|
|
Package fake provides a fake runtime implementation for testing.
|
Package fake provides a fake runtime implementation for testing. |
|
Package openshell provides an OpenShell runtime implementation for sandbox-based workspaces.
|
Package openshell provides an OpenShell runtime implementation for sandbox-based workspaces. |
|
exec
Package exec provides an abstraction for executing openshell commands.
|
Package exec provides an abstraction for executing openshell commands. |
|
Package podman provides a Podman runtime implementation for container-based workspaces.
|
Package podman provides a Podman runtime implementation for container-based workspaces. |
|
exec
Package exec provides an abstraction for executing podman commands.
|
Package exec provides an abstraction for executing podman commands. |