Skip to main content

AI Agent Security Toolkit

AI Agent Security Toolkit banner

Test and contain prompt injection in tool-using AI agents.

A Python toolkit for developers and security teams. Measure how agents respond to prompt injection, enforce which tools they can call, validate what leaves the system, and record decisions in a tamper-evident audit log.

Quickstart · Measured results · Production guide · Reference

PyPI CI License: MIT

Quickstart

Install on Python 3.11 or newer and run the built-in guarded simulator. The run needs no API key or model server.

pip install ai-agent-security-toolkit
agentsec fuzz --target builtin:guarded --quiet

Built-in simulator output

144/500 attacks succeeded (ASR 28.8%); 356 blocked, 0 errors

All 144 successes were canary echoes, where the simulator repeated a planted marker. The guarded run recorded zero successful cases of tool misuse, exfiltration, or prompt leakage. The five-minute tour walks through the output and shows how to check those outcomes in CI.

What you can do

Goal Toolkit capability
Test agents in CI agentsec fuzz scores prompt-injection tests with canaries, exports reports, and can fail CI when a threshold is exceeded. Targets and reports
Enforce tool policy ToolGuard denies undeclared tools, validates arguments, and can block side effects after a session reads untrusted content. Example policy · Integration guide
Validate outputs and audit decisions Check outputs for secrets, sensitive data, unsafe markup, and schema violations. Record decisions in a redacted, hash-chained log. Middleware and audit commands
Threat-model an agent Generate a data-flow diagram, threat register, and verification plan from a YAML system description. Worked example
Centralize enforcement · Preview Run a gateway for local models and MCP servers with identity, per-group policy, and a shared audit trail. Gateway guide

For repository checks, see configuration scanning and pinning and agent workflow scanning.

Measured results

Llama 3.1 8B evaluation

In the 0.12.0 release-candidate evaluation of Llama 3.1 8B, attack success fell from 35.5% (177/498) with the model alone to 0.4% (2/497) with the full toolkit enabled. Both guarded successes were canary echoes.

The evaluation used a 500-case matrix with a fixed model and prompt. Rates exclude cases that errored, and tool calls were recorded without execution. See the results and error details for the full evaluation, including separate tool-result experiments. The quickstart above uses a deterministic simulator.

Live Llama 3.1 8B fuzz results for 0.12.0: model alone 35.5% attack success with 66 of 198 containment hits; behind the toolkit 0.4% with 0 containment hits; tool-result delivery 4.0% and 0.0%. 0.12.0 test results: 1872 passed, 0 failed or errored, 5 skipped, 95.8% line coverage.

Full reports, including results by attack category and the simulator runs, are in docs/evidence/v0.12.0.

0.17.0: threat-model ratings and an honest gateway dashboard

0.17.0 lets a threat-model system description carry the team's own ratings (impact, likelihood, status, controls, owner) for a register row, validated against fixed scales; unrated rows render as before. The gateway /dashboard has a new server-rendered layout with no JavaScript, and no longer shows a fuzz run whose cases all errored as contained: unscored runs read "No scored cases" and per-category containment reads unknown when a report has errors.

0.16.2: patched gateway image

0.16.2 is 0.16.0 with the gateway image's Alpine packages upgraded, so it passes the pre-publication vulnerability scan. The 0.16.0 and 0.16.1 images were never published (the 0.16.1 build was blocked from the Alpine CDN). Use ghcr.io/dustystudy/ai-agent-security-toolkit:0.16.2. No Python code changed since 0.16.0.

0.16.0: Claude SDK 2.x and honest scoring of cut-off replies

0.16.0 moves the anthropic extra to SDK 2.x (anthropic>=2.0, Claude API version 2026-10-21); users pinned to SDK 0.x or 1.x keep 0.15.1. The fuzzer no longer counts a Claude reply that was cut off (max_tokens, model_context_window_exceeded, pause_turn) as the model resisting: the case is an incomplete response and fails a --max-asr gate unless the partial reply already shows a hit. Current Claude models think by default and thinking counts toward max_tokens (default 512), so raise it if many cases end that way. The example agent loops return a clear message on refusal and max_tokens and log token usage to the audit log. No gateway or request-path code changed.

0.15.1: probe-isolation runs without the DLP key

0.15.1 fixes one bug found in the gateway staging rehearsal: agentsec probe-isolation no longer needs dlp.fingerprint_key to be readable, so the rollout gate runs from a client workstation without the gateway's DLP secret. GATEWAY.md now explains how to trust an internal CA for upstreams (SSL_CERT_FILE), and scripts/staging-rehearsal/ holds the kit used for the rehearsal. No request-path code changed.

0.15.0: closing the residual risks from the 0.14.1 review

0.15.0 fixes three of the six residual risks the 0.14.1 review left open, and records why the other three are accepted (see RELEASE_CHECKLIST.md). agentsec token offboard, token revoke --user, token enable and group revocation now match user names in any letter case, so tokens minted as alice@corp.example no longer survive an IdP event for Alice@corp.example. Plain syslog and HTTP SIEM targets need a loopback IP such as 127.0.0.1: a config naming localhost for one no longer loads. SAML replay caches are bounded, the bearer NotBefore is checked, and the new saml.max_authn_age_s can require a fresh IdP sign-in. If you ran 0.14.0 with SCIM, see the upgrade note in the changelog.

Latest results on the 0.17.0 release candidate (2026-12-05, details in RELEASE_CHECKLIST.md):

Check Result
Tests (Python 3.12, Windows, local) 2380 passed, 38 skipped (symlink and POSIX-only tests), 94.9% line coverage; the CI matrix runs the rest
CI matrix (3.11-3.14 on Linux, Windows and macOS, plus security scans) All checks green
Built-in simulator, wheel install Guarded 0/200 tool misuse, exfiltration and prompt leaks, and 0/100 through tool results
Real agentsec serve with a stub model that obeys every injection 0 tool misuse and 0 exfiltration in buffer, streamed and holdback modes (140 cases each); audit chain intact. Rerun for 0.17.0
Gateway /dashboard, live Strict CSP and no script; a fuzz report whose cases all errored shows "No scored cases" and containment unknown
Container image Built from the candidate: read-only, no capabilities, uid 10001, no pip; unlisted Host 403, no identity 401 (local Docker and CI container job)
Dependency audit Locks unchanged since 0.15.1 (pip-audit clean 2026-11-28); 0 open Dependabot, code-scanning and secret-scanning alerts (2026-12-05)

The simulator and stub-model runs use no real model. No live-model run was repeated for this candidate, because the fixes do not change what the detectors catch on the evaluation set.

Gateway staging rehearsal (2026-11-28, after release). A local rehearsal of the five acceptance controls on Docker passed every check against the 0.15.0 wheel from PyPI, with a rollback to 0.14.1 and forward again. It used stand-ins for the identity proxy, model, MCP server and SIEM, so it does not replace the acceptance run in each real deployment. It found one bug, fixed on main after 0.15.0: probe-isolation needed the DLP fingerprint key on the client workstation (with 0.15.0, set the variable to any placeholder of 32 or more characters there). The same checks then passed on AWS (an AWS dev account, the published 0.15.0 image verified by attestation, security-group isolation, audit shipped to CloudWatch), and every AWS resource was deleted afterwards. Details are under R20 in RELEASE_CHECKLIST.md.

How it works

flowchart LR
  U[User and retrieved content] --> S[Screen input]
  S --> M[Model]
  M -->|Tool request| G[Enforce tool policy]
  G --> T[Tools]
  T -->|Untrusted result| S
  M -->|Text| O[Validate output]
  O --> R[Response]
  S -.-> A[Audit log]
  G -.-> A
  O -.-> A

Before a tool runs, policy checks the call and the session's exposure to untrusted content. Output validation checks the response, and the audit log records decisions across those layers.

Honest limitations

The scanner and output checks are pattern-based and can miss variants. The library provides application-level controls and requires separate OS-level isolation for code execution. The gateway is in preview, and enforcement depends on restricting direct access to upstream models and MCP servers. See the production checklist and full limitations.

Documentation

Development

See contributing for local setup and project health for CI and supply-chain checks. Report vulnerabilities through the security policy.

License

MIT

Metadata

Release files for ai-agent-security-toolkit 0.17.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 ai-agent-security-toolkit 0.17.0
File Size Uploaded Provenance Actions
ai_agent_security_toolkit-0.17.0.tar.gz 470.9 kB With provenance Details for ai_agent_security_toolkit-0.17.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ai-agent-security-toolkit 0.17.0
File Interpreter ABI Platform Actions
ai_agent_security_toolkit-0.17.0-py3-none-any.whl Python 3 none any Details for ai_agent_security_toolkit-0.17.0-py3-none-any.whl

Total release size: 751.4 kB

Release files / ai_agent_security_toolkit-0.17.0.tar.gz

Download URL ai_agent_security_toolkit-0.17.0.tar.gz
Size 470.9 kB
Tags Source
SHA-256 checksum
How to use checksums
91f2e165bfff7f431b3f029d826028dbc6658710a4f6d192ad581fa0e8be401f
BLAKE2b-256 checksum
How to use checksums
81c54348af458cb3ddd16ed3ee244d75cf4f7c5465678f6616d1736a34917dc5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 5, 2026.

Transparency log

Release files / ai_agent_security_toolkit-0.17.0-py3-none-any.whl

Download URL ai_agent_security_toolkit-0.17.0-py3-none-any.whl
Size 280.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
343752b38b155a4998f821aac39af396c247d1fb1578e31a67d84b92f8149bea
BLAKE2b-256 checksum
How to use checksums
af7d0e0fe3cc3d808f1cb84ae80711d0f2ccb8065a000df20db5f1be6bec786f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 5, 2026.

Transparency log

Security for ai-agent-security-toolkit 0.17.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for ai_agent_security_toolkit-0.17.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 5, 2026.

Transparency log

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.

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