> For the complete documentation index, see [llms.txt](https://krynix.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://krynix.gitbook.io/docs/using-the-dashboard/policies.md). Agents can also search and read this documentation through its [MCP server](https://krynix.gitbook.io/docs/~gitbook/mcp).

# Policies

A **policy** is a YAML document of rules that decide an agent's tool calls. Krynix keeps a registry of policies per organisation; you bind a policy version to an agent, and from then on every tool call that agent asks about is decided by it.

## A policy

```yaml
apiVersion: krynix.dev/v1
kind: Policy
metadata:
  name: coding-agent-guardrails
  version: "2"
  description: What a coding agent may not do on a developer machine
spec:
  scope:
    agents: ["*"]
    event_types: ["tool_call"]
  rules:
    - id: no-recursive-delete
      description: No recursive force-delete
      match:
        event_type: tool_call
        payload:
          - field: tool_name
            operator: eq
            value: Bash
          - field: arguments.command
            operator: matches
            value: "rm\\s+-[a-zA-Z]*r[a-zA-Z]*f|rm\\s+-[a-zA-Z]*f[a-zA-Z]*r"
      action: deny
      severity: critical
      message: "Recursive force-delete is not permitted."
    - id: no-secrets-in-shell
      match:
        event_type: tool_call
        payload:
          - field: arguments.command
            operator: contains
            value: "AWS_SECRET_ACCESS_KEY"
      action: deny
      severity: critical
      message: "Do not put secrets on the command line."
  defaults:
    unmatched_action: allow
```

* **Scope** says which agents and event types the policy applies to. A call outside scope is not decided by this policy.
* **Rules** are tried in order; the first match decides. Order them from most specific to most general.
* **Match** is on the event type and on payload fields, with the operators in the [Policy reference](https://krynix.gitbook.io/docs/reference/policy-reference.md): `eq`, `neq`, `in`, `not_in`, `matches` (regular expression), `contains`, `exists`, and `gt`, `lt`, `gte`, `lte` for numbers.
* **Action** is `allow`, `deny`, `redact` or `require-approval`.
* **Defaults** say what an in-scope call that matches no rule gets.

The same rule works for every agent: Claude Code's `Bash`, Codex's `exec_command` (recorded under the hook's name), a LangChain `ShellTool`, and your own code all arrive as a `tool_call` with a `tool_name` and `arguments`.

## The default policy

Every new organisation starts with one policy already in place: **`krynix-destructive-shell@1`**. It is registered and added to your [baselines](#baselines) when the organisation is created, with nothing for you to do. So from the first session, every agent's tool calls are decided by it, even before you write a policy of your own.

It denies the usual ways a shell command deletes a directory tree or wipes a disk:

| Rule                      | Blocks                                                                                                |
| ------------------------- | ----------------------------------------------------------------------------------------------------- |
| `no-recursive-delete`     | `rm -r` and `rm -rf` in any spelling, including through `sudo`, `xargs` or `bash -c`                  |
| `no-find-delete`          | `find … -delete` and `find … -exec rm`                                                                |
| `no-scripted-tree-delete` | Deleting a directory tree from a script or package tool, such as Python's `shutil.rmtree` or `rimraf` |
| `no-disk-wipe`            | Formatting a disk, overwriting one with `dd`, or `shred`                                              |

Everything else passes, including other commands that delete, such as `git clean` or `rsync --delete`. The agent is told which rule refused it, for example "The command contains a recursive delete (rm -r / rm -rf), which this org's default policy blocks".

Know its limits:

* **Developers' own cleanups are blocked too.** `rm -rf node_modules` is a recursive delete. If your developers need it, write a policy that allows what you want and replace the default, or remove the default.
* **It does not catch a command disguised on purpose**: a command built from a variable, an encoded string, or run from a script file.
* **It reads the shell command only**, the `command` argument of the tool call. A command sent in any other argument is not checked.

**To remove it**, an owner or admin presses **Change baselines** on the Policies screen and unticks it. Its text stays readable, and you can tick it again later. If your organisation was created before the default existed, or it was removed and is no longer listed, ask us to add it back.

## The Policies screen

![The Policies screen](https://3117100259-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fwf1LKKia6wIa5IW8R9Sp%2Fuploads%2Fgit-blob-ad7b318ffcfc794b307c3145af398c95c966ed03%2Fdashboard-policies-list.png?alt=media)

**Policies** in the sidebar lists every policy your organisation has registered, each with its versions (newest first), their content hashes and when each was registered. At the top is the **Baseline policies** panel (see [Baselines](#baselines)). Press **Open policy** to see one.

### Write a new policy

Owners and admins:

1. Press **New policy**.
2. Enter a **Policy name** (lower case, such as `coding-agent-guardrails`) and a **New version id** (such as `1`).
3. Write the policy in **Policy (YAML)**. The `metadata.name` and `metadata.version` in the text must match the two fields above; if they do not, the editor says so and offers **Update the policy text to match**.
4. Press **Register version**. If Krynix cannot read the text as a policy, the screen shows why and nothing is registered.

A registered policy decides nothing until you [bind it to an agent](https://krynix.gitbook.io/docs/using-the-dashboard/agents.md#policy-bindings) or make it a [baseline](#baselines).

### A policy's page

![A policy's page](https://3117100259-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fwf1LKKia6wIa5IW8R9Sp%2Fuploads%2Fgit-blob-d68b5e2d525aa99eaeff430eb2ea7661b0cc74db%2Fdashboard-policy-detail.png?alt=media)

* **Versions**: every registered version with its content hash, when it was registered, which agents it governs, and two buttons: **Edit as new version** and **Archive…**. The **Compare** column picks two versions to compare.
* **Policy text**: the YAML of the version you picked, newest by default. Click another version in the table to read it.
* **What changed**: the line-by-line difference between the two versions being compared.
* **Change audit**: every change to this policy, newest first, with when, the action, the version, who made it and the content hash. Actions are `create`, `archive`, `baseline_add` and `baseline_remove`. (A `delete` row is from before archiving existed; that version's text was not kept.)

### Change a policy

A registered version never changes, so a change is always a new version:

1. On the policy's page, press **Edit as new version** on the version to start from.
2. Enter a **New version id**. The editor starts from that version's text.
3. Edit the YAML. **What this version changes** shows the difference as you type.
4. Press **Register version**.

The new version decides nothing until you bind it. Agents bound to the old version keep it until you rebind them on the [Agents](https://krynix.gitbook.io/docs/using-the-dashboard/agents.md#policy-bindings) screen. This is deliberate: changing what governs an agent is always a step you take on the agent, never a side effect of editing a policy.

### Archive a version

Press **Archive…** on a version, then **Archive version** to confirm, or **Keep it live**. An archived version stops deciding, stays readable, and its id is never reused. A version that is bound to an agent or is a baseline cannot be archived; rebind first.

## What a decision is

An install asks Krynix before each tool call. The answer is one of:

| Verdict              | What the agent does                                                                                                                                                                                                                         |
| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **pass**             | Runs the call.                                                                                                                                                                                                                              |
| **redact**           | Runs the call with the rewritten arguments the answer carries. At a hook that cannot rewrite (Claude Code, Codex), this becomes deny.                                                                                                       |
| **deny**             | Does not run the call. The rule's message is the reason the agent sees.                                                                                                                                                                     |
| **require-approval** | There is no approval queue in the dashboard yet. At a Claude Code or Codex hook the rule's `on_timeout` applies at once: deny by default, or the call runs with `on_timeout: allow`. `@krynix/sdk` submits the call for approval and polls. |

Every decision is recorded in the session as a `decision` record with the policy, the rule, the verdict and the reason, in the same call that answered it. If the record cannot be written, the verdict is withheld: enforcement and custody are one act.

An agent with no policy bound and no baseline covering it gets no decision at all (`422 POLICY_UNBOUND`). An unconfigured organisation is never an authorisation; what the agent does then is the install's outage choice.

## Binding

* A binding is to an exact version, `name@version`. There is no "latest".
* An agent may be bound to **several** policies, one version per policy name (up to 16). Each decides the call on its own and the **most restrictive verdict wins**: deny over require-approval over redact over pass. Adding a policy can only tighten an agent.
* A policy whose scope does not cover the agent abstains. If none covers it, the decision is refused as not applicable.
* Binding is refused at write time for a version that is not registered, archived, unparseable, or out of scope for the agent, so a stored binding is always one Krynix can evaluate.

## Baselines

To change them: on the Policies screen, press **Change baselines** in the **Baseline policies** panel, tick the versions every agent should be decided by, and press **Save baselines**. Saving applies to the next call of every agent in the organisation.

The organisation's **baselines** are policy versions that decide every call in the organisation, registered agent or not, bound or not, beside each agent's own policies and under the same strictest-wins rule. Use them for the rules nobody may opt out of. Owners and admins set the list; every add and remove is written to the policy's change audit.

An agent with no policy of its own under a baseline is **enforced**, and the Agents screen says "No policy of its own; decided by org baselines".

## Versions are immutable

A registered version never changes. Saving a policy registers a **new version**; the form refuses a version id already used, and the API answers `409 POLICY_VERSION_EXISTS` if a client tries. Evidence cites a policy only as `name@version`, so what decided a call last March must read the same next March.

**Archiving** a version stops it deciding and keeps its text: still readable by `name@version`, still resolvable by the verifier for sessions decided under it, gone from the lists, and its id never reusable. A version an agent is bound to, or that is a baseline, cannot be archived (`409 POLICY_IN_USE`); rebind first.

Every version's text is readable on the policy page, newest by default, any other on request. The page also lists which agents each version governs.

## Change audit

Every registration, archive, baseline add and baseline remove is written with the actor and the time, per policy and organisation-wide. The actor is a user id or email; `system` means the write was made with auth disabled and is unattributed.

## Policies in the Krynix packages

The same YAML, the same engine. `krynix evaluate --trace run.jsonl --policy policies/` checks a recorded trace after the fact and exits non-zero on a violation (`1` error, `2` critical, `3` approval needed), for CI. `@krynix/sdk` and the MCP gateway evaluate a policy file before each call in your own process. The policy format also carries data-flow rules (`spec.tools`, `spec.flow`) the gateway enforces to block the lethal trifecta; the hosted decision point does not evaluate those today.
