sandbox

package
v1.0.0 Latest Latest
Warning

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

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

Documentation

Overview

Package sandbox provides OS-level sandboxing for agent-executed commands.

enforce.go — adds a sandbox enforcement mode

Package sandbox wraps a shell command in an OS-level jail so the model's `bash` calls are confined: it may read freely but write only inside the workspace (plus temp and toolchain caches) and reach the network only when allowed. This is the *enforcement* layer beneath the permission rules (*policy*): a permitted command still cannot escape the box.

Supported backends: macOS Seatbelt (sandbox-exec), Linux Landlock (kernel 5.13+). On every other OS, or when the kernel support is missing, Command falls back to running unwrapped (see Available). Confining the in-process file-writer built-ins is handled separately, in package tool/builtin.

Index

Constants

This section is empty.

Variables

View Source
var ErrSandboxRequired = fmt.Errorf("sandbox enforcement: no isolation available — set sandbox.mode = \"warn\" to allow, or install AppContainer (Windows) / Landlock (Linux 5.13+) / sandbox-exec (macOS)")

ErrSandboxRequired is returned when sandbox enforcement is active but the platform cannot provide isolation.

Functions

func Available

func Available() bool

Available probes whether the kernel supports landlock (5.13+).

func BlockedFetchIP

func BlockedFetchIP(ip net.IP) bool

BlockedFetchIP reports whether ip is an address that must not be reached by outbound HTTP clients (web_fetch, MCP plugin connections). Covers private, link-local, unspecified, and CGNAT ranges.

func Command

func Command(spec Spec, shell, command string) ([]string, bool)

Command returns args that re-exec the current binary as a landlock wrapper. The wrapper applies landlock, then execs the real command. The second return is always true when enforcement is active.

func Enforce

func Enforce() string

Enforce returns the current enforcement mode string.

func LandlockExec

func LandlockExec(args []string)

LandlockExec is the --landlock-exec re-exec entry point called from main(). Parses args, applies landlock, then execs the target command. Never returns (calls os.Exit on error or execs on success).

func SandboxExec

func SandboxExec(args []string)

SandboxExec is a stub — the --sandbox-exec re-exec path is Windows-only.

func SetMode

func SetMode(m Mode)

SetMode changes the sandbox enforcement mode.

func WrapProcess

func WrapProcess(pid int, spec Spec) error

WrapProcess is a no-op on non-Windows platforms — OS-level sandbox confinement is applied in-process (Seatbelt on macOS, Landlock on Linux) before exec, not after start.

Types

type Mode

type Mode int32

Mode controls how the sandbox handles unavailable isolation.

const (
	// ModeWarn logs a warning but runs without sandbox (current default).
	ModeWarn Mode = iota
	// ModeEnforce refuses to run if sandbox is unavailable.
	ModeEnforce
)

type Spec

type Spec struct {
	Mode       string
	WriteRoots []string
	Network    bool
}

Spec describes how to confine one command. The zero value (Mode == "") does not enforce, so an unconfigured caller runs commands unchanged.

Jump to

Keyboard shortcuts

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