agentleash
Python safety harness for AI agents that touch mon
Created on 20th May 2026
•
agentleash
Python safety harness for AI agents that touch mon
The problem agentleash solves
AI agents that touch money (pay-per-API calls, autonomous purchases, on-chain bots) are starting to ship in production, but the safety primitives haven't caught up. A small bug or a malicious prompt can drain a Stripe key, fan out unbounded paid LLM calls, or post to a wrong endpoint before anyone notices.
agentleash is a single Python context manager that puts a leash on each agent run:
- USD-per-run + per-call caps (token-budget-py under the hood; agent halts cleanly when cap hits)
- Egress allowlist (wildcard hostnames; e.g. *.stripe.com only)
- Optional tool-arg JSON Schema gate so bad args never reach the side-effectful function
- Append-only JSONL audit log; tool args are sha256-hashed by default so PII / secrets never land on disk
It's the dollars-side companion to birddog (egress side, also today) and pairs with agentvet / agentsnap / agenttrace.
Challenges I ran into
Three things ate the most time.
-
token-budget-py API mismatch. Tests kept failing on
BudgetPoolhaving nousd_usedattribute. Fix was calling.snapshot().usd_usedinstead of reading state directly. Once I read the lib's source the API was obvious; lesson was to drop into the dep's code earlier, not later. -
PII in audit logs. First version dumped tool args verbatim into the JSONL, which means a Stripe customer ID or a personal email lands in plaintext on disk. Switched to sha256-hashing each arg by default so the audit trail still proves a call happened without leaking content.
-
Where to halt. A naive cap check at the start of
tool()misses the fact that the LLM has already produced output costing tokens. Moved the budget check to after the LLM call returns but before the side-effectful tool runs, so the agent halts at the latest safe point - the network/payment side-effect doesn't happen, but you don't lose the LLM output you already paid for.
Tracks Applied (1)
Using LocusFounder to Build a Business!
Technologies used
