Skip to content

Governance

Continue in the series →

Every tool call in keelson, whether a rib tool, a workflow prompt node, or the agent’s own built-in shell and file edits, passes through one policy engine. The engine is a single ordered stack: an operator floor of builtins plus any policies the installed ribs contribute. It runs on all four surfaces (chat, a workflow prompt node, a rib agent turn, and the /api/mcp gateway), so a rule you set holds wherever a tool runs. A tool call an external agent makes over /api/mcp passes the same stack (denylist, ask_on_shell, redact), so a governance rule covers those callers too.

Out of the box the engine only enforces the operator tool denylist. Approvals, budgets, and redaction are opt-in builtins, each enabled by one environment variable. This guide turns them on; the rib contract covers contributing a policy from a rib.

A policy returns one of three decisions for an event. The stack is walked in order and the first deny wins, so any policy can veto a call a later one would allow.

DecisionEffect
allowNo opinion, the call proceeds. On a tool result or a node’s output, an allow that carries replacement text substitutes it: this is how redaction works.
denyShort-circuits. The agent receives the reason as a tool error, or the tool is dropped from the set offered to the model.
askPauses for a human. Accept becomes allow, reject or a timeout becomes deny. With no approval channel wired, an ask degrades to deny.

The engine evaluates at several points in a turn: when the tool set is projected to the model, before a specific call runs (with its arguments), once before a turn starts (carrying the running token and turn usage, which backs budgets), after a tool result returns but before the model reads it, and on a workflow node’s assembled output before it flows downstream. A builtin only adds cost at a phase some policy actually reads, so an unused phase is free.

Set KEELSON_ASK_ON_SHELL=1 to enable the ask_on_shell builtin. It pauses for human approval before any shell or file-mutating call: keelson’s own Bash, Edit, Write, MultiEdit, and NotebookEdit tools, and the canonical shell tools a rib might register.

This covers the agent’s own built-in capabilities too, not just keelson tools. Copilot routes its built-in shell and write permission requests through the engine, and Claude’s built-in Bash / Edit / Write now route through it as well, so an ask_on_shell prompt fires whether the write came from a keelson tool or the agent reaching for its own.

Terminal window
KEELSON_ASK_ON_SHELL=1 keelson start

A pending approval surfaces two ways. In the app it appears as an in-chat prompt, published over the snapshot WebSocket on the keelson:policy:approvals key. From the CLI, list and resolve them:

Terminal window
keelson approval list
keelson approval resolve <id> accept # or: reject

Accept lets the call proceed (later policies still apply); reject denies it with a reason. An approval that no one answers within five minutes auto-rejects, so a forgotten prompt fails closed rather than hanging the turn. When more than one policy asks about the same call, the engine coalesces them into a single prompt.

Two builtins cap a session’s spend, where a session is one chat conversation or one workflow run. KEELSON_TURN_BUDGET=<n> limits model-calling turns; KEELSON_COST_BUDGET=<tokens> limits accumulated input plus output tokens. Both check once before each turn. Leaving a variable unset, blank, or non-positive leaves that builtin off.

Terminal window
KEELSON_TURN_BUDGET=40 KEELSON_COST_BUDGET=2000000 keelson start

They are a downgrade gate, not a hard wall. Once the ceiling is reached, a turn is denied only while it runs on an expensive model: a premium cost tier, or a metered per-token login. A turn on a cheaper or flat-rate subscription model keeps going. The denial message tells you to switch models. So the budget pushes spend off your metered model rather than killing the session outright. A model keelson cannot price is treated as expensive, failing closed.

Set KEELSON_REDACT_PATTERN=<regex> to enable the redact builtin. Every match of the pattern is replaced with [REDACTED] in a tool’s result before the model consumes it, and in a workflow prompt node’s output before it flows to a dependent node. Use it to scrub a secret a tool might surface.

Terminal window
KEELSON_REDACT_PATTERN='sk-[A-Za-z0-9]{20,}' keelson start

Alternation covers several patterns at once, for example (sk-[A-Za-z0-9]{20,}|ghp_[A-Za-z0-9]{36}). A blank or unset value leaves the builtin off. A pattern that is invalid, or one that risks catastrophic backtracking (ReDoS) against adversarial tool output, is reported and ignored, so a bad value disables redaction rather than wedging the server.

KEELSON_WORKFLOW_TOOL_DENYLIST is the always-on floor: a comma-separated list of tool names no workflow prompt node may use, subtracted on top of whatever a node’s own allowed_tools permits. It is the one governance control active without opt-in, and it cannot be overridden by a node or a rib.

Terminal window
KEELSON_WORKFLOW_TOOL_DENYLIST=Bash,Write keelson start

KEELSON_APPROVAL_REVIEWER=off is its sibling for approval gates. A workflow’s approval node may declare a reviewer that answers the gate when it approves with high confidence; this floor disables every such reviewer so each gate pauses for a human. See the approval node reference.

The path_confinement builtin is always registered, alongside the operator denylist. It stays inert until a rib agent turn declares its own working roots: when a turn carries allowedDirectories, the builtin denies any tool call whose file paths or shell arguments canonicalize outside those roots. It realpath-canonicalizes both the roots and each candidate path before comparing, so a symlink inside an allowed root that points elsewhere cannot be traversed to escape confinement.

A rib that runs an agent turn against a scoped directory gets confinement for free. A sandboxed chat turn declares its granted roots too, so keelson and rib tools there stay inside them. Workflow prompt nodes and MCP calls declare no roots, so the builtin allows everything there.

The sandbox confines what an agent’s own tools and a workflow’s commands can touch at the operating-system level: which paths they read and write, whether they reach the network, and which environment variables they see. It is on by default and fails closed: when a turn or node is sandboxed but nothing on the host can enforce it, it fails with a message that names the fix, rather than running unconfined.

RunsConfined by
Workflow bash and script nodesKeelson’s sandbox runtime: macOS Seatbelt through the MXC executor. Outcome mxc.
Copilot, Claude, and Codex turns (chat and prompt nodes)The provider’s own sandbox, given the same policy. Outcome provider.
Pi turnsPi’s shell runs through Keelson’s sandbox runtime; its file tools are path-gated in process. Outcome provider.
The stub and gateway providersNothing to confine: they run no tools of their own, so a sandboxed turn runs as is. Outcome off, backend unneeded.

Every bash, script, and prompt node records its outcome and backend on node_done and in the run trace (sandboxed · seatbelt, sandboxed · copilot, unsandboxed, no tools to confine), and downstream nodes read it as KEELSON_NODE_<id>_SANDBOX. In chat, /sandbox status prints the same answer for the open conversation.

The first rule that speaks wins:

  1. KEELSON_SANDBOX=required, the operator floor. It holds the sandbox on; /sandbox off, --no-sandbox, and sandbox: { enabled: false } cannot undo it.
  2. The most specific choice: a chat turn’s own sandbox (from --sandbox, --no-sandbox, or a pending /sandbox), or a node’s sandbox.enabled.
  3. The saved choice: the conversation’s (/sandbox on|off), or the workflow’s top-level sandbox.enabled.
  4. KEELSON_SANDBOX=on or off, which replaces the config default.
  5. sandbox.default in config.json, true when unset.

A client sends a choice only when the user made one, so an unset conversation follows the server’s default rather than whatever the client last assumed.

A sandboxed bash or script node starts from this profile, then the operator’s sandbox config, the workflow’s sandbox block, and the node’s sandbox block merge over it. Path lists and env union; network.outbound takes the most specific value. The operator’s filesystem.denied lands last, so no author grant can shadow it.

GrantDefault for bash and script nodes
Read-writeThe working directory, the run’s artifacts directory, and a worktree’s shared git directory.
Read-onlyKeelson’s bundled bin, the home’s scripts and node_modules, git’s config files (~/.gitconfig, ~/.config/git/config, ignore, attributes), the toolchain prefixes that exist (/Applications, /opt/homebrew, /usr/local, ~/.bun, ~/.cargo, ~/.rustup, ~/.local, ~/.nvm, ~/.volta, ~/.pyenv, /nix), and the absolute directories on PATH. System directories stay readable.
Denied~/.ssh, ~/.aws, ~/.azure, ~/.gnupg, ~/.config/gh, ~/.config/glab-cli, ~/.docker, ~/.kube, ~/.netrc, ~/.npmrc, ~/.git-credentials, ~/.config/git/credentials, ~/Library/Keychains, ~/.claude, ~/.codex, ~/.copilot, keelson’s database files, server.json, and config.json.
NetworkOutbound denied, loopback denied.
EnvironmentOnly KEELSON_*, PATH, LANG, LC_ALL, TERM, ARTIFACTS_DIR, and names the profile’s env allows. HOME, TMPDIR, and the uv and bun caches move into a per-node scratch directory. Tokens and keys in the server’s environment are dropped.

A sandboxed prompt node, and a sandboxed chat turn, hand the provider a lighter profile: the working directory (for a node, also its artifacts directory and a worktree’s shared git directory) writable, git’s config files readable so the agent can run git, outbound network denied, plus the operator’s sandbox config. The provider’s own sandbox decides what else stays readable.

A workflow that declares webSearchMode: live researches on the open web, so its sandboxed prompt nodes get outbound network unless the workflow or the node sets network.outbound itself. Its bash and script nodes keep the default denial; grant them network per node when they need it. Without this, an agent told to fetch sources under a network-denied sandbox can report every finding as unverifiable and the run still succeeds.

A workflow a rib contributes, from its workflows/ folder or its code, also gets the rib’s package directory and its data directory (<home>/rib-<id>) read-only on every node, so the rib’s scripts, prompts, pipelines, and config are reachable without the author spelling out install paths. These grants never restrict a write: when a writable root covers or sits inside one of them (a rib run from its own checkout), the grant is skipped and the writable root stands. The workflow’s own sandbox block layers on top. Sandboxed shells always see KEELSON_HOME, since HOME points into scratch.

A run with a worktree gets the worktree and the shared git directory, not the main checkout, so a tracker kept beside .git (such as .beads) is out of reach. A path that starts with $REPO_ROOT in a workflow’s sandbox block resolves against the main checkout (git’s main worktree, which is also right for a submodule or a separate git dir), so a node can grant exactly that directory without naming the host path or widening to the whole checkout. Outside a checkout the node fails closed; the operator’s config does not take the token.

Opt out as narrowly as the work allows. A node that only needs the network can keep the rest of its confinement:

nodes:
- id: fetch-docs
sandbox: { network: { outbound: allow } }
bash: curl -fsSL https://example.com/spec.json > "$ARTIFACTS_DIR/spec.json"
- id: open-pr
# forge needs the keychain-held token and the network
sandbox: { enabled: false }
bash: forge pr create --fill
ScopeHow
One nodesandbox: { enabled: false } on the node.
One workflowsandbox: { enabled: false } at the workflow’s top level; a node can still turn it back on.
One conversation/sandbox off in chat (CLI or app), or keelson chat --no-sandbox.
Everything, from config"sandbox": { "default": false } in config.json.
Everything, from the environmentKEELSON_SANDBOX=off.

The bundled workflows opt out only the nodes that cannot run confined: those that call forge (it reads its token from the keychain and needs the network), push or fetch with git, run the project’s tests or the keelson CLI through a nested bun, or read and write caller-supplied paths outside the project. Each opt-out carries a one-line comment saying why. smoke-test stays fully sandboxed.

A sandboxed node on a host without the runtime fails like this:

sandbox required but unavailable: @microsoft/mxc-sdk is not installed; run `keelson sandbox install` or set `sandbox: { enabled: false }` on the node

The two fixes are to install the runtime, or to opt the node out. When the reason is a provider that cannot sandbox, the message says to switch providers instead, because installing the runtime would not help. Under KEELSON_SANDBOX=required the message says the floor ignores enabled: false. A chat turn fails the same way with SANDBOX_UNAVAILABLE. A Copilot turn that fails because the Copilot CLI in use does not support the sandbox names COPILOT_CLI_PATH; see Sandbox.

The runtime exists for macOS 15 or later on Apple silicon only. On Linux, Windows, an Intel Mac, or older macOS, every sandboxed bash and script node and every pi turn fails closed until that platform’s runtime ships, so run those hosts with KEELSON_SANDBOX=off or sandbox.default: false.

  • Keelson and rib tools run in the server process. A sandboxed chat turn path-gates their arguments to the turn’s roots (see Filesystem confinement); in a workflow prompt node they are not confined.
  • Git’s config files (~/.gitconfig and ~/.config/git/config, ignore, and attributes) are readable to a sandboxed agent so it can run git. Git’s credential stores (~/.git-credentials, ~/.config/git/credentials) are denied to bash and script nodes. For prompt nodes and chat turns they are only not granted, and whether a path outside the grants is readable depends on the provider’s sandbox: Codex reads outside the working directory.
  • Pi’s file tools (read, write, edit, grep, find, ls) run in process and are path-gated, not OS-isolated. The gate checks a path and then pi opens it, so a path swapped between the two (a check-then-use window) is not caught. When an asked-for file is missing, pi’s read retries similar names (a screenshot’s AM/PM spelling, Unicode-normalized forms, curly quotes) that the gate did not check. A denied path that does not exist yet is matched by spelling only.
  • Hard links that alias denied content are readable through their allowed path on every backend, the OS sandbox included, which filters by path. The pi gate refuses a hard link only when the denied path is that very file.
  • Copilot’s built-in file tools run inside the Copilot CLI process and are policy-checked, not OS-isolated.
  • env is not mapped for Copilot, Claude, or Codex. Only Keelson’s runtime passes the profile’s variables in.
  • network.allowedHosts fails closed on macOS: Seatbelt filters egress all or nothing, so a profile that allows outbound traffic to listed hosts is refused rather than widened to every host. Codex refuses it too. Copilot and Claude enforce it in their own sandboxes.
  • network.loopback on macOS also opens inbound connections, so a listener bound to 0.0.0.0 inside the sandbox is reachable from the network. Keep it off unless a node must reach the keelson server.
  • A nested bun inside a sandboxed bash node, or inside a sandboxed agent’s shell, sees an empty environment: Bun drops its environment when it cannot read a parent directory. A script node with runtime: bun works; for a shell that runs bun test, opt the node out.
  • Rib agent turns, where a rib runs its own agent, do not take the sandbox; they get filesystem confinement when the rib declares roots.
  • The repository’s own .git, hooks and config included, stays writable to a sandboxed node or agent, as it is unsandboxed: it is the project’s, and a worktree’s shared git directory is granted so commits work.
  • Worktree setup (git fetch, bun install) runs on the host before any node starts, unsandboxed.
  • The runtime is Apple-silicon only for now; other hosts fail closed, as above.

A rib contributes policies through its contributePolicies hook. The harness collects them at boot and appends them to the same ordered stack, after the builtins, namespaced as rib:<id>:<policy>. They share every semantic above: the three decisions, first-deny-wins, the ASK round-trip, and the coalescing of duplicate prompts. A malformed policy is dropped with a warning rather than crashing the boot. See contributePolicies in the contract for the shape.

On the workflow surface the context also carries workflowName and nodeId, so a rib policy can scope itself to its own workflow’s node rather than firing on every workflow-surface turn. Both are absent everywhere else, and on an older harness that does not populate them, where they read as undefined: a check like ctx.workflowName === "x" does not error there, it simply stops matching, so a policy that must hold against an older harness decides for itself whether an absent name fails open or closed. The rib contract documents the full context.

A rib can reach another rib’s tool, but crossing that line is default-deny: with no grant, it is refused before it reaches the policy engine. The operator opts a caller in per caller → target → tool, in config.json:

{
"crossRibGrants": {
"swarm": {
"beads": ["beads_ready", "beads_show", "beads_update", "beads_close"]
}
}
}

"*" covers every tool the target owns; list tool names to narrow it. The equivalent KEELSON_CROSS_RIB_GRANTS env string (caller:target:tool triples, ;-separated) unions with the config rather than replacing it. Prefer the config file for a standing grant, since an env-only grant lapses whenever the server starts from a shell that never exported it.

The grant gates two paths: a rib’s explicit callTool, and the tools projected onto a rib’s agent turn. The second is easy to miss: a rib that offers an agent a capability backed by a sibling rib’s tools gets nothing without the grant, and the tools are simply absent rather than refused, so the agent cannot report the gap. If a rib’s agent says it lacks a tool you expected it to have, check the grant before the rib.

The turn’s log is where that denial surfaces. When a rib explicitly requests sibling-owned tools no grant clears, the server writes one [rib-agent-turn] warning per caller and owner pair, naming the dropped tools and the grant that would clear them. A rib can also ask before it spends a turn: getToolReachability on the rib contract returns a per-name status, and cross-rib-denied is the missing grant.

The check runs first, ahead of the policy stack, so an ungranted call never surfaces an approval prompt for a call that would be denied regardless. See Configuration for the config key, the env string, and the cross-rib call timeout.

A rib starting a catalog workflow through startWorkflow follows the same order. It is default-deny, the operator opts a rib in per workflow name under ribWorkflowGrants, and the grant is checked before the policy stack. A granted start is then evaluated as a workflow_run tool call on the rib surface, so a policy can still deny it. The rib can read and cancel the runs it started. See Configuration for the config key and the env string.

Answering those runs’ approval gates is a second grant, ribApprovalGrants, in the same order: default-deny, opted in per workflow name, checked before the policy stack, then evaluated as a workflow_respond call on the rib surface. Without it the gate waits for you. A rib answers only on runs it started, and a paused run’s status hands it the files the gate names, such as the plan, so it can judge what it approves. See Configuration.

  • Configuration: every KEELSON_* variable, including the governance ones, in one table.
  • The CLI: the keelson approval command group.
  • The rib contract: contributing a policy from a rib with contributePolicies.
  • Operating the server: the running server the approval round-trip needs.