sandbox

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 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 runs the commands KairoCode starts inside the operating system's sandbox, after Codex (ADR 0005): writes only under the session's working directory and the temporary directories, no network unless asked, and the directories that hold KairoCode's and other agents' settings kept out of reach. Nothing else in KairoCode starts a command another way (AGENTS.md); where there is no sandbox, Command fails rather than run without one.

Index

Constants

This section is empty.

Variables

View Source
var ErrUnavailable = errors.New("sandbox: not available on this system")

ErrUnavailable: there is no sandbox here. The caller asks the user every time instead of running without one (ADR 0005: fail closed).

View Source
var Protected = []string{".git", ".kairocode", ".opencode", ".claude", ".agents", "kairocode.json", ".github/hooks", ".github/copilot"}

Protected names, directly under a writable directory, are not written even there: they hold the repository's history and the settings, hooks and permissions of KairoCode and other agents (ADR 0005), kairocode.json among them. A command in the sandbox cannot change what it is allowed to do. copilot's hooks and settings are paths in .github (ADR 0018), the rest of which stays writable.

On Linux only those that exist are kept: one that does not exist yet can be made (see platformCommand).

Functions

func Available

func Available() error

Available says whether commands can be confined here: bubblewrap is installed and may make the namespaces (it cannot under some AppArmor settings, or in a container that forbids user namespaces).

func Command

func Command(ctx context.Context, p Policy, dir string, argv ...string) (*exec.Cmd, error)

Command makes the command to run argv in dir under p. dir must lie inside p.Root; a directory a model gave that does not is refused, never taken as a place to write.

func Env

func Env(p Policy) []string

Env is a command's environment: this process's, less anything that looks like a secret (ADR 0005, invariant 6), with KAIROCODE_SANDBOX saying how the command is confined.

func HideFromLoopback

func HideFromLoopback(dirs ...string)

HideFromLoopback adds directories a loopback command must not see, for the Unix sockets in them: the daemon's data directory, whose socket would let a command approve its own calls (ADR 0031). Each process that starts loopback commands says it (the daemon, a background job's runner). On macOS the sandbox already keeps such sockets out of reach; on Linux it hides them.

func SocketDir

func SocketDir() (dir string, done func(), err error)

SocketDir makes a Loopback command's own temporary directory, under /tmp (short: a Unix socket's path is cut at about 104 bytes), only this user's; done removes it once the command has ended.

Types

type Mode

type Mode int
const (
	// ReadOnly: nothing may be written, nothing reached over the network.
	ReadOnly Mode = iota
	// WorkspaceWrite: writes under the working directory and the temporary
	// directories only.
	WorkspaceWrite
	// FullAccess: no sandbox. Only for a call the user approved (escalation).
	FullAccess
)

func (Mode) String

func (m Mode) String() string

type Policy

type Policy struct {
	Mode Mode
	// Root is the session's working directory, as fixed when the session
	// started. A directory the model names counts only inside it.
	Root string
	// Writable are more directories to allow writes under (settings).
	Writable []string
	// Network allows network access.
	Network bool
	// AllowGit lets the command write .git (the git tools only: ADR 0005).
	AllowGit bool
	// Loopback allows, without Network, what stays on this machine (ADR
	// 0031): TCP and UDP on localhost, and Unix sockets in SocketDir alone,
	// which is the command's TMPDIR. Other Unix sockets (the daemon's,
	// tmux's) stay out of reach: through them a command could approve its
	// own calls or type into a terminal.
	Loopback bool
	// SocketDir is the Loopback command's own temporary directory, made by
	// SocketDir().
	SocketDir string
}

Policy is how a command is confined.

Directories

Path Synopsis
Package sandboxtest skips a test that starts commands in KairoCode's sandbox where there is none, and notes so: inside another sandbox (an agent's, or KairoCode's own) one cannot be started (ADR 0031), and scripts/check.sh says how many tests did not run (KAIROCODE_SKIPPED).
Package sandboxtest skips a test that starts commands in KairoCode's sandbox where there is none, and notes so: inside another sandbox (an agent's, or KairoCode's own) one cannot be started (ADR 0031), and scripts/check.sh says how many tests did not run (KAIROCODE_SKIPPED).

Jump to

Keyboard shortcuts

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