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 ¶
const ( Bubblewrap = "bwrap" Landlock = "landlock" Seatbelt = "seatbelt" )
Mechanisms that confine commands.
const HelperCommand = "__sandbox"
HelperCommand is the hidden daemon subcommand that confines itself with Landlock and runs the command after it.
Variables ¶
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.
var Detect = sync.OnceValue(detect)
Detect finds how this system confines commands, once.
ErrUnavailable is returned for a command whose sandbox this system cannot apply.
Functions ¶
func RunHelper ¶
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 ¶
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 ¶
DenialHint explains a failed command's output that reads like p refused it; empty when it does not.
func (Policy) Describe ¶
Describe says in a sentence what p lets a command do; empty for the zero Policy.
func (Policy) Resolve ¶
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.
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.
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.