Skip to main content

agentguard-py

PyPI Python License: MIT

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. Wire check() 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.maxRequests is accepted as an alias for budget.max_requests for parity with the JS docs.

See the JS sibling's README for the full design notes.

Metadata

Release files for agentguard-firewall 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for agentguard-firewall 0.1.0
File Size Uploaded Provenance Actions
agentguard_firewall-0.1.0.tar.gz 6.3 kB Without provenance Details for agentguard_firewall-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for agentguard-firewall 0.1.0
File Interpreter ABI Platform Actions
agentguard_firewall-0.1.0-py3-none-any.whl Python 3 none any Details for agentguard_firewall-0.1.0-py3-none-any.whl

Total release size: 13.0 kB

Release files / agentguard_firewall-0.1.0.tar.gz

Download URL agentguard_firewall-0.1.0.tar.gz
Size 6.3 kB
Tags Source
SHA-256 checksum
How to use checksums
24cb420e0eb2e648f412931f69920575f6196d19d7d1260fc78010d85a69ab91
BLAKE2b-256 checksum
How to use checksums
cde354c7d81232f3a0d618ac89d8289a90a577b9edd5dbec6105832cbe0ccdcd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Release files / agentguard_firewall-0.1.0-py3-none-any.whl

Download URL agentguard_firewall-0.1.0-py3-none-any.whl
Size 6.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
086c1d49ba3bad3e7e7b9aab1082241a46abc47661fb4fd2b03a8cbd2263ca5a
BLAKE2b-256 checksum
How to use checksums
b9bd002cd3cf86833ea49ab5008c28d6915a71aa6a58e58d235b4a8ac657f6c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.4

Security for agentguard-firewall 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page