How does policy as code work?
The application asks, the policy engine decides, and the application enforces. Open Policy Agent states the design in one line: “OPA decouples policy decision-making from policy enforcement” (OPA docs, read 16 November 2026). The caller sends structured JSON describing the request, and the engine evaluates it against the policies. A rule for an AI agent’s refund tool, in Rego v1 syntax, where OPA 1.0 made the if keyword mandatory (OPA v0 upgrade guide, read 16 November 2026):
package agent.refunds
default allow := false
allow if {
input.tool == "issue_refund"
input.amount <= 200
input.agent.scope == "support"
}
Anything not explicitly allowed is denied. The rule lives outside the model, so no prompt can argue its way past it.
What tools are used for policy as code?
Four engines cover most policy as code in practice, each deciding in a different place.
| Tool | Language | Where it decides | Worth knowing |
|---|---|---|---|
| Open Policy Agent | Rego | Any service that queries it | CNCF graduated project since 4 February 2021 (CNCF) |
| OPA Gatekeeper | Rego | Kubernetes admission | “Policy Controller for Kubernetes” (GitHub) |
| HashiCorp Sentinel | Sentinel | HashiCorp products | Advisory, soft-mandatory and hard-mandatory levels (docs) |
| Cedar | Cedar | Application authorization | Policy in Amazon Bedrock AgentCore evaluates agent tool calls at the gateway (AWS docs) |
All four sources read 16 November 2026. Sentinel’s three levels are the same allow, ask and deny split agents need: advisory logs a failure, soft-mandatory can be overridden, and hard-mandatory cannot.
Why does policy as code matter for AI agents?
An agent picks its tools at run time, so a permission written in its prompt is only a suggestion. Policy as code moves the decision to the tool boundary, where an agent policy engine checks identity, parameters and scope before anything executes, and a deny actually stops the call. AWS describes its AgentCore policies as intercepting “all agent traffic” through the gateway and evaluating each request “before allowing tool access” (source above). Keep agent authorization deterministic and let tool approval handle the exceptions. Scope each policy to least privilege, version it, review every change, and test it with allow and deny cases as you would code.
How do we use policy as code at Soba Labs?
Every substantive change our automated routines make arrives as a pull request. A gate then decides whether it merges, for code, documents and this website alike. The gate runs deterministic checks first: a versioned file of forbidden patterns that fences what may be published, a lint on added lines, a secret scan and a guard on our legal entity name. Then a language model judges the diff, and a written rubric in the same repository is its only valid ground for rejecting a change; a verdict citing any rule outside it goes to a person instead. A separate workflow merges once every check is green.
Two choices keep it honest. A pull request that edits the gate’s own rules waits for a human, so the policy cannot rewrite itself. And our agents’ decision rights, which actions they take alone, which they propose, which they ask about, are set by the action, never by how confident the agent feels. We explain why a measured signal beats a model’s own confidence in deterministic confidence gates.