sandbox

package
v0.2.0-rc9 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: Apache-2.0 Imports: 16 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 runs one verify command inside bubblewrap.

The layout: the host read-only, with DD's state, the host owner's secrets, the socket dirs, $HOME and /tmp hidden behind empty, size-capped tmpfs mounts; the job's own worktrees and a per-run tmp and cache dir bound back writable; each clone's .git read-only; fresh /proc and /dev. No network of its own: a socat bridge inside forwards 127.0.0.1:ProxyPort to the egress proxy's Unix socket, bound in read-only. The environment is built by the caller, never inherited.

Every bound path is checked first: no symlink anywhere on it, inside one of the run's Roots, and never equal to or holding a hidden path. A path that fails is a layout the sandbox refuses (ErrUnavailable), never a mount: a symlink planted by the agent can't bind a secret in.

The command runs in a new PID namespace whose first process is bwrap itself, with --die-with-parent: killing the launcher kills every process the command started.

Index

Constants

View Source
const ProxyPort = 18080

ProxyPort is where the egress bridge listens inside the sandbox. The sandbox has its own network namespace, so the port is always free.

Variables

View Source
var ErrUnavailable = errors.New("verify sandbox unavailable")

ErrUnavailable wraps every reason the sandbox cannot start.

View Source
var FixedHidden = []string{"/run", "/var/run", "/tmp"}

FixedHidden are hidden in every sandbox: the socket dirs and /tmp.

View Source
var ProxyURL = "http://127.0.0.1:" + strconv.Itoa(ProxyPort)

ProxyURL is the value of HTTP(S)_PROXY inside the sandbox.

Functions

func Reason

func Reason(err error) string

Reason is err as `dd-worker status` and the hello show it.

Types

type Launcher

type Launcher struct {
	Bwrap string
	Socat string
	// Size: bwrap takes --size (caps a tmpfs). DisableUserns: bwrap takes
	// --disable-userns (no further user namespaces inside).
	Size          bool
	DisableUserns bool
}

Launcher is the host's bwrap and socat, and the bwrap options it has.

func Find

func Find() (Launcher, error)

Find looks the tools up on PATH. A host without them, or not Linux, has no sandbox, and verify is skipped there.

func (Launcher) Args

func (l Launcher) Args(r Run) ([]string, error)

Args is the bwrap argument list for r (after the bwrap binary), or an ErrUnavailable when a bound path fails the layout checks.

func (Launcher) Command

func (l Launcher) Command(ctx context.Context, r Run) (*Proc, error)

Command is the sandboxed command. Cancelling ctx kills the whole sandbox.

func (Launcher) SelfTest

func (l Launcher) SelfTest(ctx context.Context) error

SelfTest is the startup check behind verify_sandbox.v1 (V9). It runs the sandbox with the verify layout's parts (a hidden dir, a read-only bind, a writable dir, the egress bridge) and checks each: the hidden file is gone, the read-only dir refuses a write, the writable one takes it, a CONNECT to an allowed host is tunnelled and one to another host is refused. It needs no network: the allowed host is a fake target in this process. The error, if any, wraps ErrUnavailable and reads as a reason.

type Proc

type Proc struct {
	Cmd *exec.Cmd
	// contains filtered or unexported fields
}

Proc is one sandboxed command.

func (*Proc) Reached

func (p *Proc) Reached() bool

Reached reports, after Wait, whether the sandbox got as far as the command. False is a setup failure: bwrap or the bridge failed to start.

func (*Proc) Start

func (p *Proc) Start() error

Start starts the sandbox.

type Run

type Run struct {
	// Command runs as `sh -c Command` in Dir.
	Command string
	Dir     string
	// Home is hidden like Hide; HOME should point at it.
	Home string
	// Hide are paths hidden behind an empty tmpfs (a dir) or /dev/null (a
	// file). FixedHidden and Home are added. A path that does not exist
	// is skipped: there is nothing to hide.
	Hide []string
	// Roots are where every Writable and ReadOnly path must lie (the
	// worker's job dir and clones dir).
	Roots []string
	// Writable are bound back read-write after the hiding: the job's
	// worktrees and the run's tmp and cache dirs.
	Writable []string
	// ReadOnly are bound read-only last, over anything writable: each
	// clone's .git and each worktree's .git file.
	ReadOnly []string
	// Env is the whole environment (KEY=VALUE).
	Env []string
	// ProxySock is the egress proxy's socket ("": no network at all).
	ProxySock string
}

Run is one command and the layout it runs in. Paths are host paths.

Jump to

Keyboard shortcuts

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