Network egress firewall for AI agents. Declarative allow/deny list of hosts your agent tools may reach. Python port of @mukundakatta/agentguard.
Project description
agentguard-py
Network egress firewall for AI agents. Declarative allow/deny list of hosts your agent tools may reach. Zero runtime dependencies.
Python port of @mukundakatta/agentguard.
Install
pip install agentguard-py
Usage
from agentguard import policy, check, PolicyViolation
p = policy({
"network": {
"allow": ["api.openai.com", "*.anthropic.com"],
"deny": ["billing.openai.com"],
"methods": ["GET", "POST"],
},
})
decision = check(p, "https://api.openai.com/v1/chat", {"method": "POST"})
# Decision(action='allow')
decision = check(p, "https://evil.example.com/")
# Decision(action='deny', reason='not_in_allowlist', detail='evil.example.com')
Plugging into HTTP clients
check() is the decision primitive. Wrap your favorite HTTP client around it:
import httpx
from agentguard import policy, check, PolicyViolation
p = policy({"network": {"allow": ["api.openai.com"]}})
class GuardedClient(httpx.Client):
def send(self, request, **kw):
d = check(p, str(request.url), {"method": request.method})
if d.action == "deny":
raise PolicyViolation(d.reason, d.detail, str(request.url), request.method)
return super().send(request, **kw)
Pattern matching
| Pattern | Matches |
|---|---|
"api.openai.com" |
exact host |
"*.example.com" |
example.com and any subdomain (api.example.com, *.api.example.com, ...) |
"*" |
everything (handy as a catch-all in deny) |
Deny rules win over allow rules.
API differences from the JS sibling
- No
firewall(spec, fn)-- Python doesn't have AsyncLocalStorage / a clean global-fetch monkey-patching equivalent. Wirecheck()into your HTTP client of choice (see above). - No
wrap_fetch()for the same reason. Policy,Decision, and the inner network/budget objects are immutable dataclasses.budget.maxRequestsis accepted as an alias forbudget.max_requestsfor parity with the JS docs.
See the JS sibling's README for the full design notes.
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 agentguard_firewall-0.1.0.tar.gz.
File metadata
- Download URL: agentguard_firewall-0.1.0.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
24cb420e0eb2e648f412931f69920575f6196d19d7d1260fc78010d85a69ab91
|
|
| MD5 |
40a2c9f5db89d8161b6e64c1e50ad045
|
|
| BLAKE2b-256 |
cde354c7d81232f3a0d618ac89d8289a90a577b9edd5dbec6105832cbe0ccdcd
|
File details
Details for the file agentguard_firewall-0.1.0-py3-none-any.whl.
File metadata
- Download URL: agentguard_firewall-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
086c1d49ba3bad3e7e7b9aab1082241a46abc47661fb4fd2b03a8cbd2263ca5a
|
|
| MD5 |
338f5e27ff9078db7c858e4a0f37b98e
|
|
| BLAKE2b-256 |
b9bd002cd3cf86833ea49ab5008c28d6915a71aa6a58e58d235b4a8ac657f6c0
|