Governance
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.
The decision model
Section titled “The decision model”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.
| Decision | Effect |
|---|---|
allow | No 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. |
deny | Short-circuits. The agent receives the reason as a tool error, or the tool is dropped from the set offered to the model. |
ask | Pauses 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.
Approvals
Section titled “Approvals”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.
KEELSON_ASK_ON_SHELL=1 keelson startResolving an approval
Section titled “Resolving an approval”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:
keelson approval listkeelson approval resolve <id> accept # or: rejectAccept 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.
Budgets
Section titled “Budgets”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.
KEELSON_TURN_BUDGET=40 KEELSON_COST_BUDGET=2000000 keelson startThey 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.
Redaction
Section titled “Redaction”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.
KEELSON_REDACT_PATTERN='sk-[A-Za-z0-9]{20,}' keelson startAlternation 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.
The operator denylist
Section titled “The operator denylist”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.
KEELSON_WORKFLOW_TOOL_DENYLIST=Bash,Write keelson startKEELSON_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.
Filesystem confinement
Section titled “Filesystem confinement”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.
Sandboxed execution
Section titled “Sandboxed execution”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.
What confines what
Section titled “What confines what”| Runs | Confined by |
|---|---|
Workflow bash and script nodes | Keelson’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 turns | Pi’s shell runs through Keelson’s sandbox runtime; its file tools are path-gated in process. Outcome provider. |
| The stub and gateway providers | Nothing 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.
How a turn or node decides
Section titled “How a turn or node decides”The first rule that speaks wins:
KEELSON_SANDBOX=required, the operator floor. It holds the sandbox on;/sandbox off,--no-sandbox, andsandbox: { enabled: false }cannot undo it.- The most specific choice: a chat turn’s own
sandbox(from--sandbox,--no-sandbox, or a pending/sandbox), or a node’ssandbox.enabled. - The saved choice: the conversation’s (
/sandbox on|off), or the workflow’s top-levelsandbox.enabled. KEELSON_SANDBOX=onoroff, which replaces the config default.sandbox.defaultinconfig.json,truewhen 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.
The default profiles
Section titled “The default profiles”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.
| Grant | Default for bash and script nodes |
|---|---|
| Read-write | The working directory, the run’s artifacts directory, and a worktree’s shared git directory. |
| Read-only | Keelson’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. |
| Network | Outbound denied, loopback denied. |
| Environment | Only 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.
Opting out
Section titled “Opting out”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| Scope | How |
|---|---|
| One node | sandbox: { enabled: false } on the node. |
| One workflow | sandbox: { 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 environment | KEELSON_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.
When the sandbox cannot run
Section titled “When the sandbox cannot run”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 nodeThe 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.
What the sandbox does not cover
Section titled “What the sandbox does not cover”- 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
promptnode they are not confined. - Git’s config files (
~/.gitconfigand~/.config/git/config,ignore, andattributes) are readable to a sandboxed agent so it can run git. Git’s credential stores (~/.git-credentials,~/.config/git/credentials) are denied tobashandscriptnodes. Forpromptnodes 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’sreadretries 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.
envis not mapped for Copilot, Claude, or Codex. Only Keelson’s runtime passes the profile’s variables in.network.allowedHostsfails 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.loopbackon macOS also opens inbound connections, so a listener bound to0.0.0.0inside the sandbox is reachable from the network. Keep it off unless a node must reach the keelson server.- A nested
buninside a sandboxedbashnode, or inside a sandboxed agent’s shell, sees an empty environment: Bun drops its environment when it cannot read a parent directory. Ascriptnode withruntime: bunworks; for a shell that runsbun 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.
Policies from ribs
Section titled “Policies from ribs”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.
Cross-rib grants
Section titled “Cross-rib grants”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.
Rib workflow grants
Section titled “Rib workflow grants”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.
Related
Section titled “Related”- Configuration: every
KEELSON_*variable, including the governance ones, in one table. - The CLI: the
keelson approvalcommand group. - The rib contract: contributing a policy from a
rib with
contributePolicies. - Operating the server: the running server the approval round-trip needs.