sandbox

package
v0.99.12 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2026 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Overview

Package sandbox provides optional Docker isolation for agent shell and code tools.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnsureAgentReadable added in v0.99.12

func EnsureAgentReadable(path string) error

EnsureAgentReadable makes path readable by the sandbox container user (uid 1000). Prefer chown to the agent user with owner-only mode; if chown fails (non-root / Windows), fall back to world-accessible mode for the ephemeral temp path. Directories use modes with the execute bit so the agent can traverse into them.

func ResolvedCLIBinary added in v0.99.1

func ResolvedCLIBinary(configured string) string

ResolvedCLIBinary returns an absolute host path to a regular file usable as the sandbox flowbot CLI. configured is chat_agent.sandbox.cli_path (may be empty). Missing or invalid paths warn once and return empty.

Types

type Config

type Config struct {
	// Runtime selects the sandbox backend (docker or kern). Empty defaults to docker.
	Runtime string
	// SecurityProfile sets kern --security-profile when Runtime is kern.
	SecurityProfile string
	// Image is the container image used for Exec.
	Image string
	// Network is the Docker network mode.
	Network string
	// Memory limits container memory (e.g. "512m").
	Memory string
	// Workspace is the host workspace path bind-mounted at the same path inside the container.
	Workspace string
	// ServerURL is the Flowbot API URL injected for the flowbot CLI inside the container.
	ServerURL string
	// AccessToken is the Hub access token injected for the flowbot CLI inside the container.
	AccessToken string
	// CLIPath is an optional configured host path to a linux/amd64 flowbot CLI binary.
	// Absolute paths are used as-is; relative paths are resolved beside the server executable.
	// When empty, New looks for flowbot-cli_linux_amd64 beside the server executable.
	CLIPath string
}

Config configures Docker sandbox execution.

func ConfigFromChatAgent

func ConfigFromChatAgent(cfg config.ChatAgentSandboxConfig, workspace string) Config

ConfigFromChatAgent builds sandbox Config from chat agent settings.

type DockerRunner

type DockerRunner struct{}

DockerRunner runs commands via the Docker Engine API.

func (DockerRunner) Run

Run starts an ephemeral container, waits for exit, and returns captured output.

type Env

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

Env implements env.ExecutionEnv with host filesystem ops and sandboxed Exec.

func New

func New(cfg Config, host env.ExecutionEnv, runner Runner) *Env

New creates a sandbox ExecutionEnv. Host FS ops use env.Default when host is nil.

func (*Env) Exec

Exec runs the command inside a sandbox container with the workspace mounted.

func (*Env) MkdirAll

func (e *Env) MkdirAll(ctx context.Context, path string, perm os.FileMode) result.Result[struct{}, result.FileError]

MkdirAll creates directories on the host filesystem.

func (*Env) ReadDir added in v0.96.0

func (e *Env) ReadDir(ctx context.Context, path string) result.Result[[]env.DirEntry, result.FileError]

ReadDir lists directory entries on the host filesystem.

func (*Env) ReadFile

func (e *Env) ReadFile(ctx context.Context, path string) result.Result[[]byte, result.FileError]

ReadFile reads from the host filesystem.

func (*Env) Remove

func (e *Env) Remove(ctx context.Context, path string) result.Result[struct{}, result.FileError]

Remove deletes a path on the host filesystem.

func (*Env) WriteFile

func (e *Env) WriteFile(ctx context.Context, path string, data []byte, perm os.FileMode) result.Result[struct{}, result.FileError]

WriteFile writes to the host filesystem.

type KernRunner added in v0.99.12

type KernRunner struct {
	Client          *kern.Client
	SecurityProfile string
}

KernRunner runs commands via the kern CLI.

func (KernRunner) Run added in v0.99.12

func (r KernRunner) Run(ctx context.Context, opts RunOptions) (env.Capture, error)

Run starts an ephemeral kern box, waits for exit, and returns captured output.

type RunOptions

type RunOptions struct {
	Image       string
	Network     string
	Memory      string
	Workspace   string
	WorkDir     string
	Command     string
	Argv        []string
	ServerURL   string
	AccessToken string
	// Env is appended to the container environment (KEY=VALUE).
	Env []string
	// Stdin is process input; non-empty values are written to .flowbot-stdin under the host workdir.
	Stdin []byte
	// CLIConfigDir is a host directory bind-mounted read-only at containerCLIConfigPath.
	// When empty and AccessToken is set, DockerRunner materializes a temporary directory.
	CLIConfigDir string
	// CLIBinary is a host path to a linux/amd64 flowbot CLI file. DockerRunner copies it
	// into a temporary directory (as "flowbot") and bind-mounts that directory.
	CLIBinary string
	// CLIBinaryDir is a host directory bind-mounted read-only at containerCLIDirPath.
	// When empty and CLIBinary is set, DockerRunner materializes a temporary directory.
	CLIBinaryDir string
}

RunOptions configures one sandbox command invocation.

type Runner

type Runner interface {
	Run(ctx context.Context, opts RunOptions) (env.Capture, error)
}

Runner executes a one-shot command inside a sandbox container.

Jump to

Keyboard shortcuts

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