Documentation
¶
Overview ¶
Package libsandbox confines a spawned foreign agent to "the wall": every path out of its tools and workspace — filesystem, network, environment — is absent by construction. If confinement cannot be built, the agent is not spawned.
Index ¶
- Constants
- Variables
- func Command(ctx context.Context, spec Spec, name string, args ...string) (*exec.Cmd, error)
- func ControlPlaneEnvDeny() []string
- func DefaultEnvAllow() []string
- func DefaultEnvDeny() []string
- func EnvScrub(mode string, extraAllow, extraDeny []string) func(parent []string) []string
- func LoadCarveouts(r io.Reader) (fs []FSCarveout, net []NetCarveout, err error)
- func OverlayEnv(env []string, set map[string]string) []string
- func ParseEnvList(s string) []string
- func Preflight() error
- func ScrubModeValid(mode string) bool
- func SecretEnvDeny() []string
- func ShimMain() (handled bool, err error)
- func SystemExecDirs() []string
- type EnvPolicy
- type FSCarveout
- type NetCarveout
- type Spec
Constants ¶
const ( // ScrubOff inherits the full parent environment unscrubbed. ScrubOff = "off" // ScrubDenySecrets passes everything except the control plane and common // credential shapes (DefaultEnvDeny). ScrubDenySecrets = "deny-secrets" // ScrubStrict passes only DefaultEnvAllow plus operator additions. ScrubStrict = "strict" )
Scrub postures for a shell contenox spawns, named in operator configuration.
const ( // ModeRO grants read-only access through a filesystem carve-out. ModeRO = "ro" // ModeRW grants read-write access; use only where read-only demonstrably // breaks the agent. ModeRW = "rw" )
Access modes for an FSCarveout.
Variables ¶
var ErrInvalidCarveout = errors.New("libsandbox: invalid carve-out")
ErrInvalidCarveout is returned when a filesystem or network carve-out is malformed: bad access mode, missing justification, traversal path, or empty host.
var ErrInvalidSpec = errors.New("libsandbox: invalid spec")
ErrInvalidSpec is returned when the spec itself is unusable: no workspace, no scoped HOME, or no command to confine.
var ErrIsolation = errors.New("libsandbox: isolation failure")
ErrIsolation is returned when building or enforcing the wall fails. The wall is fail-closed, so the agent is not spawned.
var ErrLandlockUnsupported = errors.New("libsandbox: landlock unsupported by kernel")
ErrLandlockUnsupported reports that the running kernel exposes no usable Landlock filesystem ABI; it fails closed rather than running unconfined.
Functions ¶
func Command ¶
Command assembles the confined *exec.Cmd for name and args without starting it; errors wrap ErrInvalidSpec or ErrInvalidCarveout.
func ControlPlaneEnvDeny ¶
func ControlPlaneEnvDeny() []string
ControlPlaneEnvDeny is the non-negotiable veto for contenox's own control-plane variables; no Allow may re-permit these.
func DefaultEnvAllow ¶
func DefaultEnvAllow() []string
DefaultEnvAllow is the baseline of POSIX-shell essentials. HOME is absent because scrubEnv always forces the scoped HOME.
func DefaultEnvDeny ¶
func DefaultEnvDeny() []string
DefaultEnvDeny is the union of ControlPlaneEnvDeny and SecretEnvDeny used by DefaultEnvPolicy.
func EnvScrub ¶
EnvScrub returns the scrub function for a posture, or nil when inactive (ScrubOff or an unrecognized mode).
func LoadCarveouts ¶
func LoadCarveouts(r io.Reader) (fs []FSCarveout, net []NetCarveout, err error)
LoadCarveouts decodes and validates a JSON carve-out document into fs and net, rejecting unknown fields and wrapping errors in ErrInvalidCarveout.
func OverlayEnv ¶
OverlayEnv returns env with the pairs in set applied on top, de-duplicated by name and sorted. Malformed entries are dropped.
func ParseEnvList ¶
ParseEnvList splits a comma/semicolon/whitespace separated allow/deny list into trimmed entries, returning nil for empty input.
func Preflight ¶
func Preflight() error
Preflight reports whether the Landlock confinement floor can be built on this host without attempting a spawn. A non-nil error wraps ErrIsolation.
func ScrubModeValid ¶
ScrubModeValid reports whether mode is a recognized scrub posture.
func SecretEnvDeny ¶
func SecretEnvDeny() []string
SecretEnvDeny is the common credential name-shape veto, letting a loose "pass everything" allow still strip obvious secrets.
func ShimMain ¶
ShimMain is the sandbox shim entrypoint, called at the top of main(). It returns (false, nil) when not invoked as the shim; otherwise it does not return except with (true, err) wrapping ErrIsolation, which is fatal.
func SystemExecDirs ¶
func SystemExecDirs() []string
SystemExecDirs returns the confined PATH's stock binary locations in precedence order, each a subtree of the Landlock-granted system runtime.
Types ¶
type EnvPolicy ¶
type EnvPolicy struct {
// Allow lists names or globs to pass through; a glob has a single leading
// or trailing "*".
Allow []string
// Deny lists names or globs that are never passed even when Allow matches.
Deny []string
}
EnvPolicy is the operator-facing whitelist deciding which parent environment variables a confined process may inherit; Deny always wins over Allow.
func DefaultEnvPolicy ¶
func DefaultEnvPolicy() EnvPolicy
DefaultEnvPolicy is the recommended starting point: DefaultEnvAllow gated by DefaultEnvDeny.
func EnvPolicyForMode ¶
EnvPolicyForMode builds the EnvPolicy for a named scrub posture extended with extra allow/deny entries; active is false for ScrubOff and unknown modes.
func (EnvPolicy) Apply ¶
Apply is Resolve's counterpart returning surviving "KEY=VALUE" entries rather than names. Unlike scrubEnv it does not force a scoped HOME.
type FSCarveout ¶
type FSCarveout struct {
// Path is the filesystem path to make reachable (e.g. "~/.claude"); must be non-empty and must not contain a ".." traversal segment.
Path string `json:"path"`
// Mode is ModeRO or ModeRW.
Mode string `json:"mode"`
// Needs states, in plain words, why the agent breaks without this path.
Needs string `json:"needs"`
}
FSCarveout is one hole in the filesystem wall (a path, the access granted, and — mandatory — why it's needed), also the on-disk shape of a filesystem necessity-list entry.
type NetCarveout ¶
type NetCarveout struct {
// Host is the network host to allow egress to (e.g. "registry.npmjs.org").
Host string `json:"host"`
// Ports narrows the hole to specific destination ports (empty allows every port, 1-65535 each); a connection to any other port on the same host is refused and logged like a non-carve-out host.
Ports []int `json:"ports,omitempty"`
// Needs states why the agent breaks without reaching this host.
Needs string `json:"needs"`
}
NetCarveout is one hole in the network wall (a host, why it's needed, and optionally which ports), also the on-disk shape of a network necessity-list entry.
type Spec ¶
type Spec struct {
// WorkspaceRoot is the one writable directory the agent works in
// (pinned via cmd.Dir).
WorkspaceRoot string
// Home is the scoped HOME for this run, so the agent's tools resolve ~/…
// here instead of the operator's real home; carve-outs bind under it
// while ~/.ssh, ~/.aws, ~/.npmrc etc. stay unreachable.
Home string
// EnvAllow lists names of parent environment variables passed through unchanged; everything else, including any inherited credential, is dropped by default.
EnvAllow []string
// EnvSet holds explicit extra variables, overriding same-named EnvAllow values; HOME cannot be set here, it is always forced to Home.
EnvSet map[string]string
// FS lists filesystem carve-outs outside the workspace; empty means the workspace is the only reachable path.
FS []FSCarveout
// Net lists network carve-outs; empty means no route.
Net []NetCarveout
// AllowPrivateEgress opts into dialing carve-out hosts that resolve to non-public addresses (loopback, link-local, RFC1918/ULA, unspecified, multicast); default false is SSRF-safe, and it requires NetworkWall.
AllowPrivateEgress bool
// NetworkWall opts into the namespaced network wall (routeless netns plus metered per-host egress for Net carve-outs), built via an unprivileged user namespace; default off, and a spec naming Net or AllowPrivateEgress with it off is rejected.
NetworkWall bool
// Tracker observes the wall (Command's assembly lifecycle, and later every blocked bypass attempt); nil is treated as libtracker.NoopTracker.
Tracker libtracker.ActivityTracker
// SyscallTap opts into a seccomp user-notify telemetry tap (Linux only, default off) that reports execve/execveat attempts to the Tracker and always allows them to continue — it observes, it does not enforce.
SyscallTap bool
}
Spec is the confinement spec for one spawned agent. Anything not named here is absent once the wall is enforced.