Open source agent security
Agent Airlock
By Sattyam Jain, updated . On AgentDojo it blocks 86.0% of injection-to-target tool calls, as a deterministic bound rather than a model-in-the-loop rate (run ).
An in-process contract layer for AI agent tool calls.
Agent Airlock is an open-source Python library that checks each AI agent tool call before the tool runs. One decorator validates the arguments against the function's own signature in Pydantic strict mode, strips arguments the model made up, and applies the policy you set: allowed tools, roles, rate limits and budgets. A refused call comes back as a structured error with fix hints the model can retry on, not a traceback. It runs inside your process, not as a proxy or gateway. Sattyam Jain builds and maintains it; v0.13.0 was released on under Apache-2.0.
- 13,839 tests
- 92.34% coverage
- 169 releases
- v0.13.0
Install and wrap a tool
From agent-airlock on PyPI (opens in a new tab). The decorator is the whole integration; adapters cover 12 agent frameworks, among them LangChain, LangGraph, the OpenAI Agents SDK, PydanticAI, CrewAI, Google ADK and FastMCP.
pip install "agent-airlock>=0.10.3"
from agent_airlock import Airlock
@Airlock()
def transfer_funds(amount: int, to: str) -> str:
return f"Sent ${amount} to {to}"If the model sends amount="500", the call is refused (strict mode does not coerce a string to an int). If it adds force=True, that argument is stripped before the function sees it.
What it checks
A fixed sequence of gates runs before your function, and sanitising runs after it. Validation, output sanitising, the audit log and a startup-hook check are on by default; the rest is opt-in.
- Validate
- Pydantic V2 strict mode on every argument, with no type coercion. Arguments that are not in the function's signature are stripped, and a refused call returns fix hints the model can retry against.
- Authorize
- Role-based access, token-bucket rate limits, time windows, per-model-tier cost budgets and capability gating.
- Isolate
- Filesystem path checks, network egress allowlists by host and path prefix, and sandboxed execution.
- Sanitize
- PII and secret masking, output truncation and a JSON-Lines audit log.
- MCP guards
- Per-CVE guards for stdio injection, OAuth, DNS rebinding, SSRF and other MCP server flaws, tracking MCP spec revision 2026-07-28.
Measured results
Every Airlock arm in these runs uses SecurityPolicy(default_deny=True) with only the tools the task needs on its allowlist, not the library defaults, and no run uses an adaptive attacker. Null results are published beside the wins.
Indirect prompt injection, AgentDojo (all 4 suites)
86.0% of injection-to-target tool calls blocked, as a deterministic bound: 524 of the 609 attacked pairs that have a tool-call target (949 attacked in all), AgentDojo v1.2.1.
Run on . Results file for this run: Indirect prompt injection, AgentDojo (all 4 suites) (opens in a new tab)
With a model in the loop
Attack success fell from 45% to 10% on gpt-4o-mini. That is one model family on a 60-pair subset, under AgentDojo's fixed-template attack, not an adaptive one.
Run on . Results file for this run: With a model in the loop (opens in a new tab)
Claude Haiku and Claude Sonnet: a near-null (published null)
Both models resist the attack unaided (5 to 8% attack success without a defense), so the measured reduction was 0 to 1% at a 14% benign-refusal cost, over 168 pairs per arm. Against models that already resist the attack, the 86.0% deterministic bound is the informative number.
Run on . Results file for this run: Claude Haiku and Claude Sonnet: a near-null (opens in a new tab)
Prompt injection against claude-code and codex: a null result (published null)
claude-code and codex each acted on the planted script 0 of 36 times and ignored the benign twin too (0 of 36 and 0 of 35), which shows indifference to the channel, not detection.
What it does not do
- Prompt injection is not detected, only contained.
- It checks a call before it runs and cannot undo a call that ran. It ships no approval channel; you wire one to Slack, a ticket queue or a prompt.
- By default an empty allowlist allows every tool. Set default_deny=True on the SecurityPolicy to refuse tools that are not listed.
- No benchmark run uses an adaptive attacker.
Related on this site
- The Capability Lease essay: short-lived, scoped permissions for agent tool calls instead of long-lived keys.
- Agent Audit Kit: the static side, an offline scanner for MCP servers and agent pipelines.
- How many MCP servers have no authentication: the State of MCP Security 2026 census.