sandbox

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 15 Imported by: 0 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 confines the agent's shell commands: what they may write and whether they reach the network (docs/SANDBOX.md).

Index

Constants

View Source
const (
	Bubblewrap = "bwrap"
	Landlock   = "landlock"
	Seatbelt   = "seatbelt"
)

Mechanisms that confine commands.

View Source
const HelperCommand = "__sandbox"

HelperCommand is the hidden daemon subcommand that confines itself with Landlock and runs the command after it.

Variables

View Source
var DefaultCaches = []string{
	"~/.cache",
	"~/Library/Caches",
	"~/go/pkg/mod",
	"~/.npm",
	"~/.local/share/pnpm/store",
	"~/.yarn/berry/cache",
	"~/.cargo/registry",
	"~/.cargo/git",
	"~/.m2/repository",
	"~/.gradle/caches",
}

DefaultCaches are the package caches confined commands may write unless Settings.Caches replaces them.

View Source
var Detect = sync.OnceValue(detect)

Detect finds how this system confines commands, once.

View Source
var ErrUnavailable = errors.New("the shell sandbox cannot be applied")

ErrUnavailable is returned for a command whose sandbox this system cannot apply.

Functions

func RunHelper

func RunHelper(args []string) int

RunHelper is the hidden HelperCommand: args are a JSON Policy and the command line to run. It confines its own thread and runs the command from it, so the command and everything it starts stay confined.

func WorkspaceRoots

func WorkspaceRoots(dir, home string) []string

WorkspaceRoots are the directories a workspace_write command run for dir may write: dir itself unless it holds home, and the git directories of the repository dir is in, so that commits work in a worktree too.

Types

type Mode

type Mode string

Mode is how much of the machine a command may change.

const (
	Off Mode = "off"
	// WorkspaceWrite reads everything and writes only the workspace, the
	// temporary directories and the package caches.
	WorkspaceWrite Mode = "workspace_write"
	// ReadOnly writes only the temporary directories and the package caches,
	// which read-only tools such as go vet need.
	ReadOnly Mode = "read_only"
)

type Policy

type Policy struct {
	Mode Mode
	// Workspace are the project directories a workspace_write command may
	// write: the working directory and its git directories.
	Workspace []string
	// Scratch are the other writable directories: temporary ones, package
	// caches and, for workspace_write, Settings.Writable.
	Scratch   []string
	NoNetwork bool
	// Strict refuses to run a command this system cannot confine.
	Strict bool
}

Policy is how one command is confined; the zero Policy leaves it alone.

func (Policy) DenialHint

func (p Policy) DenialHint(output string) string

DenialHint explains a failed command's output that reads like p refused it; empty when it does not.

func (Policy) Describe

func (p Policy) Describe() string

Describe says in a sentence what p lets a command do; empty for the zero Policy.

func (Policy) Resolve

func (p Policy) Resolve() (Policy, error)

Resolve is p as this system applies it: p itself when it can confine it, the zero Policy when it cannot and p is not strict, and ErrUnavailable when it cannot and p is strict or cuts the network.

func (Policy) Wrap

func (p Policy) Wrap(argv []string) []string

Wrap returns the command line that runs argv under p, a Policy Resolve returned.

func (Policy) Writable

func (p Policy) Writable() []string

Writable are all the directories p lets a command write.

type Run

type Run struct {
	// WorkingDir is the session's working directory.
	WorkingDir string
	// Unattended is a full_auto session: nobody approves its commands.
	Unattended bool
	// ReadOnly is plan mode or a read-only subagent.
	ReadOnly bool
	// Env is the command's environment, read for TMPDIR.
	Env []string
}

Run is what a command runs for.

type Settings

type Settings struct {
	// Mode confines every native command; empty confines unattended ones only
	// (full_auto sessions, plan mode and read-only subagents).
	Mode Mode `json:"mode,omitempty"`
	// Network false cuts confined commands off the network.
	Network *bool `json:"network,omitempty"`
	// Writable are more directories workspace_write commands may write.
	Writable []string `json:"writable,omitempty"`
	// Caches replaces DefaultCaches when set; an empty list allows none.
	Caches *[]string `json:"caches,omitempty"`
}

Settings is setup.json's daemon.sandbox.

func (Settings) Policy

func (s Settings) Policy(r Run) Policy

Policy is how s confines a command of r.

func (Settings) Validate

func (s Settings) Validate() error

Validate rejects an unknown mode and paths that are neither absolute nor start with ~/.

type Status

type Status struct {
	// Mechanism is Bubblewrap, Landlock or Seatbelt; empty when none works.
	Mechanism string
	// Network reports whether it can cut commands off the network.
	Network bool
	// Detail names its version, or says why none works.
	Detail string
}

Status says how this system confines commands.

func (Status) Text

func (s Status) Text() string

Text is s in a line.

Jump to

Keyboard shortcuts

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