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.14.1: security review of the 0.14.0 features

0.14.1 fixes 23 bugs found in an adversarial review of the 0.14.0 gateway, identity and sandbox features, each with a regression test that fails on 0.14.0. The most serious: a user deprovisioned through SCIM could sign in again under another letter case of their name, and a tool-call approval or an async policy hook that answered after its timeout still counted. Upgrade if you use SCIM, POST /sessions/revoke, approval_timeout_s or an async policy_hook. See the changelog for every fix and the behaviour changes, such as the new agentsec_gateway_siem_dropped_records_total metric.

Latest results on the release candidate (2026-11-28, details in RELEASE_CHECKLIST.md):

Check Result
Tests (Python 3.13, Linux) 2368 passed, 6 skipped, 95.5% line coverage
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; naive 500/500
Real agentsec serve with a stub model that obeys every injection 0 tool misuse and 0 exfiltration in buffer, streamed and holdback modes; audit chain intact
Container image Read-only, no capabilities, uid 10001, no pip; health, host and identity checks pass
Dependency audit No known vulnerabilities in the hash-pinned locks

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 acceptance still has to be done for each deployment.

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.14.1

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.14.1
File Size Uploaded Provenance Actions
ai_agent_security_toolkit-0.14.1.tar.gz 459.2 kB With provenance Details for ai_agent_security_toolkit-0.14.1.tar.gz

Built distribution (wheel)

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

Total release size: 734.1 kB

Release files / ai_agent_security_toolkit-0.14.1.tar.gz

Download URL ai_agent_security_toolkit-0.14.1.tar.gz
Size 459.2 kB
Tags Source
SHA-256 checksum
How to use checksums
8b7fb8b2e4bcc91eb92669efbcaab598cdf25fbd9f6ef6aeec9496fde572ef84
BLAKE2b-256 checksum
How to use checksums
9adf6e43d93cd9bc08511d57d209aa2745abafee0c21178f8b7390e98529d9f1
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 Nov 28, 2026.

Transparency log

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

Download URL ai_agent_security_toolkit-0.14.1-py3-none-any.whl
Size 274.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
805df0b5cd6014f994873b6a23db15eba9348af13c105a0ec1017101fa3042e3
BLAKE2b-256 checksum
How to use checksums
600d4fc4578b87529e154d918ee0649560d2df7359df4502d327097eba50e582
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 Nov 28, 2026.

Transparency log

Security for ai-agent-security-toolkit 0.14.1

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.14.1.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 Nov 28, 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