Declarative action policies for AI agents — approve, deny, or escalate any tool call before execution
Project description
agent-action-policy
Declarative action policies for AI agents — approve, deny, or escalate any tool call before execution.
Install
pip install agent-action-policy
pip install agent-action-policy[yaml] # for YAML policy files
Quick Start
from action_policy import PolicyEngine, Action
engine = PolicyEngine.from_dict({
"policies": [{
"name": "no-force-push",
"match": {"tool": "bash", "args_pattern": "git push --force"},
"action": "deny",
"reason": "Force push requires human approval",
}]
})
decision = engine.evaluate(tool="bash", args={"command": "git push --force origin main"})
print(decision.denied) # True
print(decision.reason) # "Force push requires human approval"
Sandboxing vs Policy
| Sandboxing (containers) | Policy (this library) | |
|---|---|---|
| Controls | Where code runs | What the agent can do |
| Granularity | Process-level | Per-tool-call |
| Configuration | Infrastructure | YAML/Python |
| Use with | Any runtime | Any agent framework |
Sandboxing and policies are complementary. Use both.
Policy Definition (YAML)
policies:
- name: no-destructive-git
match:
tool: bash
args_pattern: "git (push --force|reset --hard|branch -D)"
action: deny
reason: "Destructive git operations require human approval"
- name: escalate-system-files
match:
tool: "~(file_write|write_file)"
path_patterns:
- "/etc/*"
- "/usr/*"
action: escalate
reason: "System file modification needs confirmation"
- name: approve-reads
match:
tool: "~(read|search|grep)"
action: approve
priority: 10 # lower = higher priority
Built-in Templates
engine = PolicyEngine.from_template("safe_coding")
| Template | What it protects |
|---|---|
safe_coding |
Blocks force-push, rm -rf, system file writes, credential access, hook skipping |
safe_browsing |
Blocks internal URLs, file:// protocol, escalates downloads |
safe_database |
Blocks DDL (DROP/TRUNCATE), escalates DELETE and WHERE-less UPDATE |
strict |
Whitelist mode — only read operations allowed, everything else denied |
Python API
# From YAML file
engine = PolicyEngine.from_yaml("policies.yaml")
# From dict
engine = PolicyEngine.from_dict({"policies": [...]})
# From template
engine = PolicyEngine.from_template("safe_coding")
# Evaluate
decision = engine.evaluate(tool="bash", args={"command": "rm -rf /"})
decision.action # Action.DENY
decision.denied # True
decision.reason # "..."
decision.policy_name # "no-rm-rf"
# Fail-closed mode (deny by default)
engine = PolicyEngine.from_template("strict", default_action=Action.DENY)
# Decorator
@engine.guard
def execute_tool(tool: str, args: dict = None):
... # raises PolicyDenied or PolicyEscalated
Pattern Matching
| Pattern type | Syntax | Example |
|---|---|---|
| Exact match | tool_name |
"bash" |
| Glob | *, ?, [...] |
"file_*" |
| Regex | ~pattern |
"~(bash|shell|exec)" |
| Args regex | any regex | "git\\s+push\\s+--force" |
| Path glob | glob or ~regex |
"/etc/*", "~\\.env$" |
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file agent_action_policy-0.1.1.tar.gz.
File metadata
- Download URL: agent_action_policy-0.1.1.tar.gz
- Upload date:
- Size: 14.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b5d5ca6ddab1148c5613cc3e041e23223d6dd566b2d58bb7efbc11a918fdfdc
|
|
| MD5 |
554b5399fa4ad67e47da3f7355ed7531
|
|
| BLAKE2b-256 |
a7f9f0597e9b1c24a2f2a08ada02c3b93cd8d1b545f1b05dfc0ffd6754e3b184
|
Provenance
The following attestation bundles were made for agent_action_policy-0.1.1.tar.gz:
Publisher:
publish.yml on QuartzUnit/agent-action-policy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
agent_action_policy-0.1.1.tar.gz -
Subject digest:
6b5d5ca6ddab1148c5613cc3e041e23223d6dd566b2d58bb7efbc11a918fdfdc - Sigstore transparency entry: 1178846423
- Sigstore integration time:
-
Permalink:
QuartzUnit/agent-action-policy@34972b6fff1dc7a4d20a0d5b0c113ed681e20369 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/QuartzUnit
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@34972b6fff1dc7a4d20a0d5b0c113ed681e20369 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file agent_action_policy-0.1.1-py3-none-any.whl.
File metadata
- Download URL: agent_action_policy-0.1.1-py3-none-any.whl
- Upload date:
- Size: 11.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
670fc60abb0e122509270344fe04c30fdffcb7fb4edec1144e9afed1fc14c2d8
|
|
| MD5 |
d8c9a56c4e10b6a46accf62fc11d0218
|
|
| BLAKE2b-256 |
20252e3b4cbd8e70e753ad408ed799daea8cbdaa1ff23524602f2ac81ff35d45
|
Provenance
The following attestation bundles were made for agent_action_policy-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on QuartzUnit/agent-action-policy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
agent_action_policy-0.1.1-py3-none-any.whl -
Subject digest:
670fc60abb0e122509270344fe04c30fdffcb7fb4edec1144e9afed1fc14c2d8 - Sigstore transparency entry: 1178846432
- Sigstore integration time:
-
Permalink:
QuartzUnit/agent-action-policy@34972b6fff1dc7a4d20a0d5b0c113ed681e20369 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/QuartzUnit
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@34972b6fff1dc7a4d20a0d5b0c113ed681e20369 -
Trigger Event:
workflow_dispatch
-
Statement type: