Policy
A policy is the set of rules that decides each action. Every workspace has one active policy. The owner signs each version, and each decision records the version it was made under.
The shape of a policy
A policy is a JSON document with two fields.
{
"default": "allow",
"rules": [
{
"id": "no-recursive-delete",
"effect": "deny",
"when": "action.tool == 'Bash' && action.attrs.command.contains('rm -rf')",
"reason": "recursive delete is not permitted"
},
{
"id": "external-email",
"effect": "escalate",
"when": "action.tool == 'email.send' && !action.target.endsWith('@acme.example')",
"reason": "email leaving the company needs a human"
}
]
}
| Field | Meaning |
|---|---|
default | "allow" or "deny". What happens when no rule matches. |
rules | An ordered list. The first rule whose condition is true decides. |
rules[].id | A name for the rule. It appears on receipts. It must be unique and must not be empty. |
rules[].effect | allow, deny or escalate. escalate means ask a human. |
rules[].when | The condition. An expression that is true or false. |
rules[].reason | A sentence shown to the agent and written on the receipt. |
Rules about ids:
- Ids that start with
mandate.orpolicy.are reserved. The engine uses them for its own verdicts. - Ids that start with
guard.belong to the guard.countersign guard onreplaces them andcountersign guard offremoves them.
Any other field in the document is an error.
A new workspace starts with {"default":"allow","rules":[]}. With that policy, each passport alone decides.
Labels on a rule
A rule can carry tags: up to eight short labels that say what the rule is there for, such as a regulation or an internal control.
{"id": "customer-data-export", "effect": "deny", "when": "action.tool == 'db.export'", "reason": "bulk export of customer data is not permitted", "tags": ["gdpr"]}
A label is lower-case letters, digits, dots and dashes, 40 characters at most. Labels never change a decision. The Controls report counts what each label's rules blocked and held. In the console, a rule's card has a Counts towards field for them.
The rule language
Conditions are written in CEL, the Common Expression Language. A condition can read four values and call one extra function.
action: what the agent asked for
| Name | Type | Meaning |
|---|---|---|
action.tool | text | The tool name, for example Bash or payments.send. |
action.target | text | What the action touches: a file path, a URL, a payee. Empty when the caller sent none. |
action.attrs.<name> | text | A fact the caller sent. All facts are text. |
action.cost | whole number | The cost in minor units. 0 when there is none. |
action.currency | text | The currency of the cost. |
action.session | text | The session id the caller sent. |
Write a fact whose name is not a plain identifier with brackets: action.attrs['arg.repo'].
mandate: the agent's passport
| Name | Type | Meaning |
|---|---|---|
mandate.agent | text | The agent's name. |
mandate.id | text | The passport id. |
mandate.principal | text | The owner's name as written on the passport. |
mandate.ans_name | text | The agent's ANS name, or empty. |
mandate.ans_host, mandate.ans_version | text | The two parts of the ANS name, or empty. |
mandate.ans_key | true or false | True when the agent signs with its ANS identity key. |
mandate.tier | text | The passport's risk tier: low, medium, high, critical, or empty when none is set. |
mandate.owner | text | The passport's business owner, or empty. |
peer: the counterparty's ANS status
peer.status, peer.host, peer.ans_name, peer.log, peer.registered and peer.live. These are filled only when Agent Name Service support is on. Otherwise peer.status is unchecked. See Agent Name Service support.
approved
True when this ask is a re-attempt of an action a human approved. You rarely need it. The engine applies approvals for you.
glob(pattern, text)
A wildcard match. * stands for any run of characters, including none. There is no other special character.
glob('*.env*', action.target)
glob('mcp__github__*', action.tool)
Text functions
CEL's own text functions work on any text value: ==, !=, .contains(), .startsWith(), .endsWith() and .matches(). matches() takes an RE2 regular expression. The guard's rules use it:
action.attrs.command.matches(r'\bgit\s+reset\s+[^;&|]*--hard\b')
How a decision is made
The engine works through four stages. The offline verifier runs the same function, so a recorded decision can always be recomputed.
- The passport's hard limits. These come first and no rule can override them.
- The tool is not in the passport's
tools: blocked, rulemandate.tool_not_granted. - The ask has a cost in a different currency: blocked, rule
mandate.currency. - The cost is over the per-action cap: blocked, rule
mandate.per_action_cap. - The cost would take spending past the budget: blocked, rule
mandate.budget.
- The tool is not in the passport's
- The policy's rules, top to bottom. The first rule whose condition is true decides.
- A
denyrule blocks the action. The decision is final. - An
escalaterule holds the action for a human. - An
allowrule lets it continue to stage 3.
- A
- The passport's approval terms. These apply unless a rule already asked for a human.
- The tool is in the passport's
escalatelist: held, rulemandate.escalate_tool. - The cost is over the passport's
escalate_over: held, rulemandate.escalate_over.
- The tool is in the passport's
- The default. If nothing has blocked or held the action and no rule matched, the policy's
defaultapplies. The rule on the receipt ispolicy.default.
Three points follow from this order.
- An
allowrule does not skip the passport's approval terms. A tool listed in the passport'sescalatestill waits for a human. - An approval turns a held action into an allowed one. It never overrides a block.
- With
"default": "deny", an action that matches no rule is blocked with the reason "no rule allows this action".
When a rule reads a fact the action does not have
If a rule reads action.attrs.command and the action has no command fact, the rule is skipped. It cannot be true. The next rule is tried.
Any other evaluation error blocks the action and names the rule, with the reason "rule could not be evaluated".
Facts sent by the hook
The hook for coding agents sends these facts with each ask.
| Fact | Value |
|---|---|
kind | The kind of action. See below. |
app | Which agent sent it: claude, codex, gemini, cursor, grok, hermes, openclaw or copilot. This is the hook's --format value. Without --format the hook detects it, and a Codex call is then reported as claude, because the two send the same field names. A Claude Code hook that Grok CLI starts reports grok. |
user | The operating system account the agent runs under on that machine, for example ada. |
host | The machine's short name, for example ada-macbook. |
cli | The build of countersign that sent the ask, for example 2026.11.25.2. Builds older than that do not send it. See Updating. |
cwd | The working directory. |
channel | OpenClaw only: where the request to the agent came from, as OpenClaw names it, for example telegram or cli. |
command | The shell command, first 1,000 bytes cut at a whole character, with credentials blanked. |
program | The name of the program the command runs, for example git. Settings typed in front of it are passed over: for DB_HOST=db psql it is psql. |
file_path | The file path, for file tools. Also sent as action.target. |
url | The URL, for web tools. Also sent as action.target. |
mcp_server | The MCP server name, for tools named mcp__<server>__<tool>, and for Grok CLI's <server>__<tool>. |
mode | monitor when the hook is recording only. Absent when it is enforcing. |
stops | revoked when a recording-only hook stops the tool once its passport is revoked (build 2026.11.29.2 on). Absent otherwise. |
With --facts minimal the hook sends only kind, app, user, host, program, mcp_server, mode and stops. Rules that read command, file_path, url or action.target then never match.
The MCP gateway sends mcp_server, host, user (the gateway on the same machine only) and each top-level text, number or true/false argument of the call as arg.<name>. It also sends risk, risk_source, tool_hash and tool_changed, which say what the server claims about the tool. See Tool risk in the MCP gateway. The SDKs send whatever attrs your code passes.
The kind fact
Different agents use different names for the same tool. Claude Code calls its shell tool Bash. Gemini CLI calls it run_shell_command. The hook sorts each tool name into a kind, so one rule covers every agent.
kind | Tool names (matched in any letter case) |
|---|---|
shell | Bash, Shell, run_shell_command, exec_command, powershell, run_terminal_cmd, run_terminal_command, terminal, exec |
read | Read, read_file, read_many_files, view, NotebookRead, hashline_read |
write | Write, write_file, create, create_file |
edit | Edit, MultiEdit, replace, apply_patch, str_replace, NotebookEdit, edit_file, search_replace, hashline_edit, StrReplace, EditNotebook, patch |
search | Grep, Glob, LS, list_directory, search_file_content, codebase_search, file_search, list_dir, hashline_grep, search_files |
web | WebFetch, WebSearch, web_fetch, google_web_search, fetch, web_search, XSearch, x_search, web_extract |
agent | Agent, Task, spawn_agent, spawn_subagent, delegate_task, sessions_spawn |
mcp | Any tool whose name starts with mcp__ or mcp_. From Grok CLI, a name of the form server__tool that is not one of its own tools |
other | Anything else |
A rule on the kind:
{
"id": "prod-deploy-needs-human",
"effect": "escalate",
"when": "action.attrs.kind == 'shell' && action.attrs.command.contains('--prod')",
"reason": "Production deploys need a human."
}
kind is set by the hook. Asks from the SDKs and the MCP gateway carry it only if your code sends it. The first ask that countersign start records has the kind setup.
More examples
These rules are taken from the product's tests and from the starting policies in the console.
Block destructive shell commands:
{
"id": "no-destructive-shell",
"effect": "deny",
"when": "action.attrs.kind == 'shell' && (action.attrs.command.contains('rm -rf') || action.attrs.command.contains('push --force'))",
"reason": "Destructive shell commands are not permitted for agents."
}
Keep credential files off limits. This rule reads action.target, which is the path an agent's file tool was given (Read, Edit, Write and the like). It does not stop a shell command that reads the same file, such as cat .env.production: a shell command has no target. Codex reads files with shell commands only, so on Codex this rule never applies. The digest flags a command that touches a credentials file, and nothing blocks it unless you add a rule on action.attrs.command:
{
"id": "secrets-off-limits",
"effect": "deny",
"when": "glob('*.env*', action.target) || glob('*/.ssh/*', action.target) || glob('*credentials*', action.target)",
"reason": "Agents may not read credential files."
}
Block on a named target:
{
"id": "no-prod",
"effect": "deny",
"when": "action.target == 'prod'",
"reason": "not prod"
}
Block on a fact your own agent sends:
{
"id": "known-payees-only",
"effect": "deny",
"when": "action.tool == 'payments.send' && action.attrs.payee_on_file == 'false'",
"reason": "Payments to payees not on file are not permitted."
}
Ask a human on a fact:
{
"id": "vip-needs-human",
"effect": "escalate",
"when": "action.tool == 'crm.update' && action.attrs.tier == 'vip'",
"reason": "Changes to VIP accounts need a human."
}
Block statements with DROP, DELETE or ALTER in them. The rule looks for those three words in capitals, anywhere in the statement. It does not stop UPDATE, INSERT or TRUNCATE, or drop table typed in lower case. It works only when the agent's own code sends the statement as the statement attribute:
{
"id": "no-schema-changes",
"effect": "deny",
"when": "action.tool == 'db.query' && (action.attrs.statement.contains('DROP') || action.attrs.statement.contains('DELETE') || action.attrs.statement.contains('ALTER'))",
"reason": "Agents may not drop, delete or alter."
}
Ask a human over an amount. This is the form the console's rule builder writes for "the cost is over". Costs are in minor units, so this is 100.00:
{
"id": "large-spend",
"effect": "escalate",
"when": "action.cost > 10000",
"reason": "Spending over 100 needs a human."
}
Facts are always text. Compare them with text: action.attrs.payee_on_file == 'false'.
Changing the policy
Every change is a new version. The owner signs it and it is recorded in the ledger. Decisions made before the change keep pointing at the version that was in force.
From the command line
countersign policy # show the active version and its source
countersign policy set policy.json # sign and activate a new version
policy set checks that the file compiles before it signs. An error names the rule.
In the console
The Policy page shows each rule as a sentence.
- Add rule starts from scratch or from a ready-made rule.
- A rule has one or more conditions. Each condition picks a field (the tool, the target, a fact, the cost, the agent), a comparison and one or more values. With several conditions, choose whether all or any must be true.
- The comparisons for text are: is, is not, contains, does not contain, starts with, does not start with, ends with, does not end with, matches pattern, does not match pattern. "Matches pattern" uses
glob. For cost they are: is over, is under. - Then sets the effect: Block it, Ask a human, or Allow it.
- Tell the agent sets the reason.
- Edit as code shows the expression. An expression the builder cannot represent stays in code view.
- The arrows reorder rules. Order matters, because the first match decides.
- If no rule matches sets the default: "Allow what the passport grants" or "Block it".
- Sign and activate signs the new version with your key. The button is enabled only when the policy compiles.
The tester
The console's Try it panel, on the Policy page, tests one imagined action against your rules. It uses your unsaved changes, so you can try a rule before you sign it. Nothing is recorded.
Fill in:
- As agent: which passport to test as.
- Tool and, if you wish, Target.
- A value for each fact your rules read.
- Cost, if any.
- Counterparty's ANS status, shown when a rule reads
peer.
The panel answers "Would be allowed", "Would be blocked" or "Would wait for a human", and names the rule that decided. If the passport decided, it says so.
The tester needs at least one active passport. There is no CLI command for the tester. The same check is available over the API as POST /v1/policy/test. See the API reference.
Two other ways to try a rule before it stops anything:
- Send one real ask with
countersign askand read the verdict. This is recorded. - Run the agent in recording-only mode. A rule that would block is recorded as
would blockand the agent is not stopped. See Guard. - Turn on a starter rule for coding agents from the card at the top of the Policy page. Each one shows one thing it stops, one it lets through, and what it would have stopped or held in your own record of the last 30 days, with the commands themselves. One press signs the ones you switched on, and they are added to the rules you have. Add rule holds the starter rules for an MCP gateway and the ready-made rules, which go into the draft so you can check them against history before you sign.
Replaying a draft rule against past actions is not built.