write-policy
Skill25 starsChanged 5 months agoMITView on GitHub
Write or modify a Hexgate YAML policy from a plain-language request — tool modes, argument constraints, caller attributes (ctx.*), run budgets (run.*), cross-run usage quotas (agent_usage.*, user_usage.*), network egress (net.http_request / net.tcp_connect), agent admission and reach, roles and inheritance, or policy modules — then prove it with `hexgate policy validate` and `hexgate policy test` dry-runs. Use when asked to write, draft, generate, extend, tighten, or explain a Hexgate policy, or to turn "the agent may only…" into policy YAML.
In this repository9 other files it gives its agents.
- AGENTS.mdAGENTS.md
- hexgate/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- hexgate/CLAUDE.mdCLAUDE.md
- film-demoSkill
- integration-testsSkill
- pr-descriptionSkill
- run-platformSkill
- write-adrSkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 2 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 14
Before writing anything, read these two pages in full.
- Distinctive: line 27
Read the others when you need a detail, and prefer them over this file if they disagree:
- Very specific: line 45
Follow the six steps of writing-a-policy.mdx: pin down the inputs, record what an existing policy allows today, restate the intent as a …
- Very specific: line 85
If uv fails building biscuit-python on Python 3.14, add --python 3.13.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Write a Hexgate policy
The user describes intent in prose; you produce a policy YAML that validates, plus a set of dry-run cases that prove it does what they asked. A policy you have not run through the CLI is not finished.
Read first
Before writing anything, read these two pages in full. They hold the method and the traps, and they are the source of truth this skill follows:
docs/policy/writing-a-policy.mdx: the method, step by step;docs/policy/common-mistakes.mdx: agent reach, egress, safe patterns, scope, usage caps and trust.
The paths are from the repository root, and from the workspace in the eval
sandbox. If they are not there, read the same pages through the Hexgate MCP
server's policy_reference tool (sections writing-a-policy and
common-mistakes), or at https://docs.hexgate.ai/policy/writing-a-policy and
https://docs.hexgate.ai/policy/common-mistakes.
Read the others when you need a detail, and prefer them over this file if they disagree:
| Topic | File |
| Document shape, modes | docs/policy/yaml-shape.mdx |
Constraint grammar, run.*, agent_usage.*, user_usage.* | docs/policy/constraints.mdx |
| Worked condition examples | docs/policy/writing-conditions.mdx |
Roles, policies/ dir, inheritance | docs/concepts/user-scope.mdx |
| Egress | docs/concepts/egress.mdx |
| Admission / agent reach | docs/concepts/agent-level-enforcement.mdx |
| Cross-run quotas, fail mode | docs/adr/R-USAGE-001-cross-run-usage-is-soft-and-fails-open.md |
| CLI | docs/cli/policy.mdx |
| Schema (authoritative) | hexgate/security/models.py, hexgate/security/constraints.py |
| Examples | examples/demo_policy.yaml, deploy/demo_policies/ |
Workflow
Follow the six steps of writing-a-policy.mdx: pin down the inputs, record what
an existing policy allows today, restate the intent as a decision table, write,
validate and prove, report. With the CLI, they map to these commands.
Inputs. Take tool and argument names from the agent code or its manifest
JSON; keep the manifest file to pass to validate.
Record what the policy allows today, and prove it, with policy test:
uv run hexgate policy test <file> --role billing --tool refund_order \
--args '{"amount": 500, "currency": "USD"}' [--attributes '{"department": "finance"}'] \
[--agent-usage '{"invocations_1h": 100}'] [--user-usage '{"invocations_1h": 50}'] --engine wasm--roles a,bchecks a caller holding several roles.--agent-usageand--user-usagefeedagent_usage.*anduser_usage.*; a path left out reads zero.- Pass
--engine wasmon every run, since that engine matches production. If it fails because OPA itself is unusable (opa not found,HEXGATE_OPA_BIN points to…,below the tested floor), drop the flag and say in the report that the production engine went unchecked, and why; any other wasm error is a problem in the policy to fix. policy testtakes one file. For a module tree, resolve a role to a file first withuv run hexgate policy resolve --dir <root> --role <role>, then test that file. That file holds one role only, so--roles a,bcannot run on it, and whether admission or reach is declared is judged on that role alone, while the runtime judges it across every role: dry-runs ofagent.runandagent.*keys can then differ from production.policy testreports deny foragent.handoff:*andagent.tool:*even when the policy declares no such gate, while the runtime then lets the call through: read the gate rules incommon-mistakes.mdx, not only the dry-run.
Validate until clean:
uv run hexgate policy validate <file> --max-severity warning [--manifest m.json]
uv run hexgate policy check --dir <root> [--manifest m.json] # a module treeIf uv fails building biscuit-python on Python 3.14, add --python 3.13.
Report the YAML, the decision table with each row's actual CLI result, the assumptions, and any residual risk.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

