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 ¶
ErrUnavailable: there is no sandbox here. The caller asks the user every time instead of running without one (ADR 0005: fail closed).
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 ¶
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 ¶
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.
Types ¶
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). |