sandbox

package
v1.30.0 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package sandbox provides Docker sandbox lifecycle management including creation, detection, argument building, and environment forwarding.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AgentRefFromArgs

func AgentRefFromArgs(args []string) string

AgentRefFromArgs returns the first positional (non-flag) argument from the docker-agent arg list, which is the agent file reference. Returns "" if there are no positional arguments.

func AppendFlagIfMissing

func AppendFlagIfMissing(args []string, flag, value string) []string

AppendFlagIfMissing appends "--flag value" to args unless args already contain the flag (in either "--flag value" or "--flag=value" form).

func BuildCagentArgs

func BuildCagentArgs(argv []string) []string

BuildCagentArgs takes os.Args and returns the arguments to pass after "--" to the sandbox. It strips the binary name, "--sandbox", and the first occurrence of the "run" subcommand. If the agent reference is a user-defined alias, it is resolved to its path so the sandbox (which lacks the host's user config) receives a concrete reference. It also injects --yolo since the sandbox provides isolation. Host-only flags --debug/-d, --log-file, --template, and --models-gateway are stripped because they reference host paths/logging, sandbox creation options, or settings forwarded via env var that don't apply inside the sandbox.

["cagent", "run", "./agent.yaml", "--sandbox", "--debug"] → ["./agent.yaml", "--yolo"]
["cagent", "--debug", "run", "--sandbox", "myalias"]      → ["/path/to/agent.yaml", "--yolo"]

func BuildExecCmd

func BuildExecCmd(ctx context.Context, name string, cagentArgs, envFlags, envVars []string) *exec.Cmd

BuildExecCmd assembles the `docker sandbox exec` command.

func CheckAvailable

func CheckAvailable(ctx context.Context) error

CheckAvailable returns a user-friendly error when Docker is not installed or the sandbox feature is not supported.

func Ensure

func Ensure(ctx context.Context, wd, extra, template, configDir string) (string, error)

Ensure makes sure a sandbox exists for the given workspace, creating or recreating it as needed. When template is non-empty it is passed to `docker sandbox create -t`. Returns the sandbox name.

func EnvForAgent

func EnvForAgent(ctx context.Context, agentRef string, env environment.Provider) (flags, envVars []string)

EnvForAgent loads the agent config and gathers the environment variables it requires. It returns:

  • flags: `-e KEY` args for docker sandbox exec (name only, no value)
  • envVars: `KEY=VALUE` entries to set on the exec process environment

Variables that Docker Desktop already proxies are skipped.

func ExtraWorkspace

func ExtraWorkspace(wd, agentRef string) string

ExtraWorkspace returns the directory to mount as a read-only extra workspace when the agent file lives outside the main workspace. Returns "" if no extra mount is needed (file is under wd, is not a local path, etc.).

func ResolveAlias

func ResolveAlias(name string) string

ResolveAlias returns the alias path if name is a user-defined alias, or an empty string otherwise.

func StartTokenWriterIfNeeded

func StartTokenWriterIfNeeded(ctx context.Context, dir, modelsGateway string) func()

StartTokenWriterIfNeeded starts a background goroutine that refreshes DOCKER_TOKEN into a shared file when a models gateway is configured. Returns a stop function that is safe to call multiple times (and is a no-op when no writer was started).

Types

type Existing

type Existing struct {
	Name       string   `json:"name"`
	Workspaces []string `json:"workspaces"`
}

Existing holds the name and workspaces of an existing Docker sandbox.

func ForWorkspace

func ForWorkspace(ctx context.Context, wd string) *Existing

ForWorkspace returns the existing sandbox whose primary workspace matches wd, or nil if none exists.

func (*Existing) HasWorkspace

func (s *Existing) HasWorkspace(dir string) bool

HasWorkspace reports whether the sandbox has dir mounted as a workspace.

Jump to

Keyboard shortcuts

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