Agent Audit

June 7, 2026 · View on GitHub

Find security vulnerabilities in your AI agent code before they reach production.

PyPI version Python License: MIT CI codecov Tests Docs


Why Agent Security Fails in Production

AI agents are not just chatbots. They execute code, call tools, and touch real systems, so one unsafe input path can become a production incident.

  • Prompt injection rewrites agent intent through user-controlled context
  • Unsafe tool inputs can reach subprocess/eval and become command execution
  • MCP configuration mistakes can leak credentials and expand access unintentionally

If your team ships agent features, owns CI security gates, or operates MCP servers and tool integrations, this is a high-probability risk surface rather than an edge case. You likely need this before every merge if agent code can trigger tools, commands, or external systems.

Agent Audit catches these issues before deployment with an analysis core designed for agent workflows today: tool-boundary taint tracking, MCP configuration auditing, and semantic secret detection, with room to extend into learning-assisted detection over time.

Think of it as security linting for AI agents, with 72 rules mapped to the OWASP Agentic Top 10 (2026).


Quick Start in 6 Lines

  1. Install
pip install agent-audit
  1. Scan your project
agent-audit scan ./your-agent-project
  1. Interpret and gate in CI
# Show only high+ findings
agent-audit scan . --severity high

# Fail CI when high+ findings exist
agent-audit scan . --fail-on high

--severity controls what is reported. --fail-on controls when the command exits with code 1.

Sample report output:

╭──────────────────────────────────────────────────────────────────────────────╮
│ Agent Audit Security Report                                                  │
│ Scanned: ./your-agent-project                                                │
│ Files analyzed: 2                                                            │
│ Risk Score: 8.4/10 (HIGH)                                                    │
╰──────────────────────────────────────────────────────────────────────────────╯

BLOCK -- Tier 1 (Confidence >= 90%) -- 16 findings

  AGENT-001: Command Injection via Unsanitized Input
    Location: agent.py:21
    Code: result = subprocess.run(command, shell=True, capture_output=True, text=True)

  AGENT-010: System Prompt Injection Vector in User Input Path
    Location: agent.py:13
    Code: system_prompt = f"You are a helpful {user_role} assistant..."

  AGENT-041: SQL Injection via String Interpolation
    Location: agent.py:31
    Code: cursor.execute(f"SELECT * FROM users WHERE name = '{query}'")

  AGENT-031: Mcp Sensitive Env Exposure
    Location: mcp_config.json:1
    Code: env: {"API_KEY": "sk-a***"}

  ... and 15 more

Summary:
  BLOCK: 16 | WARN: 2 | INFO: 1
  Risk Score: =========================----- 8.4/10 (HIGH)

Validation snapshot (as of 2026-05-30, v0.19.0, ground-truth dataset v2.2, 81 samples / 236 positive labels + 2 negative labels):

  • Precision 73.58%, Recall 82.63%, F1 0.778 (raw, reproducible) — TP 195 / FP 70 / FN 41
  • Footnote: an adjusted F1 of 0.84 is computable post-hoc by excluding FPs from rules added after v0.16 that are not yet labeled in GT, but it is not directly reproducible from precision_recall.py and is therefore not used as a headline figure. See docs/F1_REPRODUCTION.md. GT v2.3 refresh planned June 2026.
  • OWASP Agentic Top 10 coverage: 10/10

Reproducible from a clean clone: pip install -e packages/audit/ && python tests/benchmark/precision_recall.py --output-json results/layer1.json. Result file checked in at results/layer1_v0.19.0.json. Ground-truth label refresh for the 18 new rules (AGENT-053+) lands June 2026.

Details: Benchmark Results | Competitive Comparison


What It Detects

CategoryWhat goes wrongExample rule
Injection attacksUser input flows to exec(), subprocess, SQLAGENT-001, AGENT-041
Prompt injectionUser input concatenated into system promptsAGENT-010
Leaked secretsAPI keys hardcoded in source or MCP configAGENT-004, AGENT-031
Missing input validation@tool functions accept raw strings without checksAGENT-034
Unsafe MCP serversNo auth, no version pinning, overly broad permissionsAGENT-005, AGENT-029, AGENT-030, AGENT-033
MCP tool poisoningHidden instructions or data exfiltration in tool descriptionsAGENT-056, AGENT-057
MCP tool shadowingMultiple servers register identical tool names to override behaviorAGENT-055
MCP rug pull / driftServer tools change after initial security auditAGENT-054
No guardrailsAgent runs without iteration limits or human approvalAGENT-028, AGENT-037
Unrestricted code executionTools run eval() or shell=True without sandboxingAGENT-035
Source map leakageDebug artifacts (.map, .pdb) included in published agent packagesAGENT-110
Sub-agent privilege escalationChild agents inherit parent's full tool set without restrictionAGENT-112
Delegation without authCross-agent delegation without identity verificationAGENT-113
Auto-approve all toolsAgent auto-approves tool execution without safety classificationAGENT-117
HITL bypassHuman-in-the-loop approval bypassed via delegation or self-modificationAGENT-118
Trace suppressionAI attribution removed from git commits, logs, or outputsAGENT-119
Config hooks poisoningMalicious hooks in .claude/settings.json, .cursor/, .mcp.json (CVE-2025-59536)AGENT-120

Full coverage of all 10 OWASP Agentic Security categories. Framework-specific detection for LangChain, CrewAI, AutoGen, and AgentScope. See all rules ->


OpenClaw Support

Agent Audit is available as an OpenClaw skill on ClawHub:

npx clawhub@latest install agent-audit-scanner

Once installed, ask your OpenClaw agent:

  • "Scan my installed skills for security issues"
  • "Is this new skill safe?"
  • "Audit my OpenClaw config"

The scanner covers all 10 OWASP Agentic AI threat categories and has been validated against 18,899 ClawHub skills at 80% precision.


Who Is This For

  • Agent developers building with LangChain, CrewAI, AutoGen, OpenAI Agents SDK, or raw function-calling -- run it before every deploy
  • Security engineers reviewing agent codebases -- get a structured report in SARIF for GitHub Security tab
  • Teams shipping MCP servers -- validate your mcp.json / claude_desktop_config.json for secrets, auth gaps, and supply chain risks

Usage

# Scan a project
agent-audit scan ./my-agent

# JSON output for scripting
agent-audit scan ./my-agent --format json

# SARIF output for GitHub Code Scanning
agent-audit scan . --format sarif --output results.sarif

# Only fail CI on critical findings
agent-audit scan . --fail-on critical

# Inspect a live MCP server (read-only, never calls tools)
agent-audit inspect stdio -- npx -y @modelcontextprotocol/server-filesystem /tmp

Baseline Scanning

Track only new findings across commits:

# Save current state as baseline
agent-audit scan . --save-baseline baseline.json

# Only report new findings not in baseline
agent-audit scan . --baseline baseline.json --fail-on-new

GitHub Actions

Show GitHub Action Example and Inputs
name: Agent Security Scan
on: [push, pull_request]
jobs:
  audit:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: HeadyZhang/agent-audit@v1
        with:
          path: '.'
          fail-on: 'high'
          upload-sarif: 'true'
InputDescriptionDefault
pathPath to scan.
formatOutput format: terminal, json, sarif, markdownsarif
severityMinimum severity to reportlow
fail-onExit with error at this severityhigh
baselineBaseline file for incremental scanning-
upload-sarifUpload SARIF to GitHub Security tabtrue

Evaluation Results

Show Evaluation Details

Evaluated on the labeled benchmark in tests/ground_truth/labeled_samples.yaml (81 samples, 236 positive + 2 negative labels, GT v2.2) — reproducible via python tests/benchmark/precision_recall.py. Bandit and Semgrep numbers below were measured on the equivalent injection/RCE/credential subset that those tools can express; see BENCHMARK-RESULTS.md for methodology.

ToolRecallPrecisionF1
agent-audit (v0.19.0, raw, reproducible)82.63%73.58%0.778
Bandit 1.829.7%100%0.46
Semgrep 1.x27.0%100%0.43
Categoryagent-auditBanditSemgrep
Set A -- Injection / RCE100%68.8%56.2%
Set B -- MCP Configuration100%0%0%
Set C -- Data / Auth84.6%0%7.7%

Neither Bandit nor Semgrep can parse MCP configuration files -- they achieve 0% recall on agent-specific configuration vulnerabilities (Set B).

Full evaluation details: Benchmark Results | Competitive Comparison

How It Works

Show Architecture and Technical Notes
Source Files (.py, .json, .yaml, .env, ...)
        |
        +-- PythonScanner ---- AST Analysis ---- Dangerous Patterns
        |        |                                Tool Metadata
        |        +-- TaintTracker --------------- Source->Sink Reachability
        |        +-- DangerousOperationAnalyzer - Tool Boundary Detection
        |
        +-- SecretScanner ---- Regex Candidates
        |        +-- SemanticAnalyzer ----------- 3-Stage Filtering
        |              (Known Formats -> Entropy/Placeholder -> Context)
        |
        +-- MCPConfigScanner -- Server Provenance / Path Permissions / Auth
        |
        +-- PrivilegeScanner -- Daemon / Sudoers / Sandbox / Credential Store
                 |
                 v
            RuleEngine -- 72 Rules x OWASP Agentic Top 10 -- Findings

Key technical contributions:

  • Tool-boundary-aware taint analysis -- Tracks data flow from @tool function parameters to dangerous sinks (eval, subprocess.run, cursor.execute), with sanitization detection. Only triggers when a confirmed tool entry point has unsanitized parameters flowing to dangerous operations.

  • MCP configuration auditing -- Parses claude_desktop_config.json and MCP gateway configs to detect unverified server sources, overly broad filesystem permissions, missing authentication, unpinned package versions, tool description poisoning, cross-server tool shadowing, and baseline drift (rug pull) -- a category entirely missed by existing SAST tools.

  • Three-stage semantic credential detection -- (1) Regex candidate discovery with priority tiers, (2) value analysis with known-format matching, entropy scoring, and placeholder/UUID exclusion, (3) context adjustment by file type, test patterns, and framework schema detection.

Threat Coverage

72 detection rules covering all 10 categories of the OWASP Agentic Top 10 (2026):

OWASP CategoryRulesExample Detections
ASI-01 Agent Goal Hijack7Prompt injection, tool description poisoning, argument poisoning
ASI-02 Tool Misuse11@tool input to subprocess without validation, browser/subprocess sandbox
ASI-03 Identity & Privilege12Daemon privilege escalation, sudoers NOPASSWD, sub-agent boundary, >10 MCP servers
ASI-04 Supply Chain17Unverified MCP source, tool shadowing, baseline drift (rug pull), extension boundary, deserialization, OpenClaw skill obfuscation
ASI-05 Code Execution5eval/exec in tool without sandbox, credential store access, skill sandbox override
ASI-06 Memory Poisoning3Unsanitized input to vector store upsert, persistent session memory
ASI-07 Inter-Agent Comm1Multi-agent over HTTP without TLS
ASI-08 Cascading Failures3AgentExecutor without max_iterations
ASI-09 Trust Exploitation10Critical ops without human_in_the_loop, HITL bypass, trace suppression
ASI-10 Rogue Agents3No kill switch, no behavior monitoring, self-modification

Real-World Validation

Show Real-World Target Results

Scanned 9 open-source projects to validate detection quality:

TargetProjectFindingsOWASP Categories
T1damn-vulnerable-llm-agent4ASI-01, ASI-02, ASI-06
T2DamnVulnerableLLMProject41ASI-01, ASI-02, ASI-04
T3langchain-core3ASI-01, ASI-02
T6openai-agents-python25ASI-01, ASI-02
T7adk-python40ASI-02, ASI-04, ASI-10
T8agentscope10ASI-02
T9crewAI155ASI-01, ASI-02, ASI-04, ASI-07, ASI-08, ASI-10
T10MCP Config (100-tool server)8ASI-02, ASI-03, ASI-04, ASI-05, ASI-09
T11streamlit-agent6ASI-01, ASI-04, ASI-08

10/10 OWASP Agentic Top 10 categories detected across targets. Quality gate: PASS.

Comparison with Existing Tools

Capabilityagent-auditBanditSemgrep
Agent-specific threat model (OWASP Agentic Top 10)YesNoNo
MCP configuration auditingYesNoNo
Tool-boundary taint analysisYesNoNo
@tool decorator awarenessYesNoNo
Semantic credential detectionYesBasicBasic
General Python securityPartialYesYes
Multi-language supportPython-focusedPythonMulti

agent-audit is complementary to general-purpose SAST tools. It targets the security gap specific to AI agent applications that existing tools cannot address.

Configuration

# .agent-audit.yaml
scan:
  exclude: ["tests/**", "venv/**"]
  min_severity: low
  fail_on: high

ignore:
  - rule_id: AGENT-003
    paths: ["auth/**"]
    reason: "Auth module legitimately communicates externally"

allowed_hosts:
  - "api.openai.com"

Current Scope

Show Current Limitations and Scope
  • Current core is static analysis: Does not execute code and may miss runtime-only logic vulnerabilities.
  • Intra-procedural taint analysis: Tracks data flow within functions; no cross-function or cross-module tracking yet.
  • Python-focused: Primary support for Python source and MCP JSON configs. Limited pattern matching for other languages.
  • Framework coverage: Deep support for LangChain, CrewAI, AutoGen, AgentScope. Other frameworks use generic @tool detection rules.
  • False positives: Mitigated through semantic analysis, framework detection, and allowlists; ongoing optimization (79% FP reduction in v0.16).

Documentation

Development

git clone https://github.com/HeadyZhang/agent-audit
cd agent-audit/packages/audit
poetry install
poetry run pytest ../../tests/ -v  # 1541 tests

See CONTRIBUTING.md for full development setup and PR guidelines.

Citation

If you use agent-audit in your research, please cite:

@software{agent_audit_2026,
  author = {Zhang, Haiyue},
  title = {Agent Audit: Static Security Analysis for AI Agent Applications},
  year = {2026},
  url = {https://github.com/HeadyZhang/agent-audit},
  note = {Based on OWASP Agentic Top 10 (2026) threat model}
}

Acknowledgments

License

MIT -- see LICENSE.