Freeze the policy at start-up
Freezing a policy engine makes it reject every change after start-up, so an agent that can run code cannot grant itself a tool the policy denied.
Last updated: 14 Oct, 2026 · Agent Governance Toolkit 4.1.0
Every rule in the Writing your own policy rules lesson was added with a method call. An agent that can run code can call those methods too, which makes the policy engine itself a target. Freezing closes that door.
The one-line self-grant
The attack needs no cleverness. Any code in the same process can call add_constraint and hand a role the tool it was denied.
from agent_control_plane import PolicyEngine, AgentKernel
policy = PolicyEngine()
policy.add_constraint("support", ["order_status"])
kernel = AgentKernel(policy_engine=policy)
print("before:", kernel.intercept_tool_execution("support", "delete_account", {}) is None)
policy.add_constraint("support", ["order_status", "delete_account"]) # the attack
print("after: ", kernel.intercept_tool_execution("support", "delete_account", {}) is None)before: False after: True
The deletion was denied, then allowed, by one extra call. A tool that executes code, or anything that arrived through a dependency, can make that call.
Freezing blocks every change
Call freeze after the policy is built. Every mutating method then raises, and the message says the call is irreversible, because there is no unfreeze by design: one would be the first thing an attacker reached for.
policy = PolicyEngine()
policy.add_constraint("support", ["order_status"])
policy.freeze()
try:
policy.add_constraint("support", ["delete_account"])
except RuntimeError as exc:
print(exc)PolicyEngine is frozen — cannot perform 'add_constraint'. Call freeze() is irreversible to prevent runtime self-modification.
Even direct assignment is refused
Freezing does more than set a flag. The engine's internal dictionaries become read-only views, so reaching past the methods to assign a permission directly fails as well. Checking still works; only changing is blocked.
print("frozen:", policy.is_frozen)
try:
policy.state_permissions["support"] = {"delete_account"} # reach past the methods
except TypeError as exc:
print("direct:", exc)frozen: True direct: 'mappingproxy' object does not support item assignment
A record of every change
Every change is recorded as it happens, the freeze included, so you have a record of how the policy reached the state it is in.
policy = PolicyEngine()
policy.add_constraint("support", ["order_status"])
policy.add_constraint("readonly", ["order_status"])
policy.freeze()
for entry in policy.mutation_log: # the freeze is logged too
print(entry["operation"], entry["details"])add_constraint {'role': 'support', 'tools': ['order_status']}
add_constraint {'role': 'readonly', 'tools': ['order_status']}
freeze {}What freezing does and does not stop
- It stops every change after start-up.
add_constraint,add_custom_ruleand the rest all raise once the engine is frozen. - It stops reaching past the methods, because the permission tables become read-only views, not plain dictionaries.
- It leaves checking untouched. A frozen engine answers
check_violationexactly as before, which is why you freeze and then serve.
Before and after freezing
| Operation | Before freeze | After freeze |
|---|---|---|
add_constraint | Changes the policy | Raises RuntimeError |
| Direct dictionary assignment | Changes the policy | Raises TypeError |
check_violation | Works | Works |
freeze again | Freezes | No complaint |
Where you freeze the policy
- At the end of start-up, the moment the policy is fully built, so the serving phase runs on a policy nothing can edit.
- In any process that runs agent-chosen code, where a tool could otherwise reach the engine and widen its own permissions.
- In a test, to prove the self-grant attack raises rather than succeeds.
Related
- Previous: Writing your own policy rules
- Next: Two ways the engine checks a call
- Call
freezetwice and confirm the second call does not complain. - Freeze before the
add_constraintcalls and watch the set-up fail instead of the attack. - Print
policy.mutation_logafter a blocked change and confirm the refused call left no entry.
You understood something today that you didn't yesterday.