AI-powered secure code review and threat analysis engine
Project description
๐ ThreatSmith - Threat Modeling for the Agentic AI Era ๐ค
โโโโโโโโโ โโโ โโโ โโโโโโโ โโโโโโโโ โโโโโโ โโโโโโโโโ โโโโโโโโ โโโโ โโโโ โโโ โโโโโโโโโ โโโ โโโ
โโโโโโโโโ โโโ โโโ โโโโโโโโ โโโโโโโโ โโโโโโโโ โโโโโโโโโ โโโโโโโโ โโโโโ โโโโโ โโโ โโโโโโโโโ โโโ โโโ
โโโ โโโโโโโโ โโโโโโโโ โโโโโโ โโโโโโโโ โโโ โโโโโโโโ โโโโโโโโโโโ โโโ โโโ โโโโโโโโ
โโโ โโโโโโโโ โโโโโโโโ โโโโโโ โโโโโโโโ โโโ โโโโโโโโ โโโโโโโโโโโ โโโ โโโ โโโโโโโโ
โโโ โโโ โโโ โโโ โโโ โโโโโโโโ โโโ โโโ โโโ โโโโโโโโ โโโ โโโ โโโ โโโ โโโ โโโ โโโ
โโโ โโโ โโโ โโโ โโโ โโโโโโโโ โโโ โโโ โโโ โโโโโโโโ โโโ โโโ โโโ โโโ โโโ โโโ
ThreatSmith is an AI-powered threat modeling engine that automates established security methodologies end-to-end. It runs each stage as a fresh AI coding agent session, assembles prompts with accumulated context from prior stages, auto-detects available security scanners, and validates that each stage produces its expected deliverable. The result is a complete, structured threat model generated directly from your codebase.
No API keys. No separate billing. No token budgets to manage. If you have a Claude Code or Codex subscription, you already have everything you need. Point ThreatSmith at a repository and get a full threat model.
Supported Frameworks
ThreatSmith ships with pluggable framework packs. Each pack defines its own stages, prompts, output files, and reference material. Select a framework with --framework or let the default run.
4QF + STRIDE (default)
The Four Question Framework combined with STRIDE provides a streamlined, 4-stage threat model focused on system modeling, threat identification, mitigations, and validation. It is practical for teams that want actionable results without the overhead of a full risk-centric methodology.
PASTA
PASTA (Process for Attack Simulation and Threat Analysis) is a 7-stage, risk-centric methodology that produces structured security artifacts: data flow diagrams, threat inventories, vulnerability assessments, attack trees, and prioritized remediation roadmaps. It is thorough, but the manual effort involved makes full adoption rare โ until now.
Use Cases
- Persist threat models in Git as context for AI-powered secure code review. Commit the
threatmodel/directory to your repository. When AI coding agents review PRs or audit code, they can reference the threat model for context on trust boundaries, known vulnerabilities, and attack surfaces. - Give AI coding agents security context to write secure code. With the threat model in the repo, agents writing new features can consult it to understand data sensitivity classifications, required security controls, and known attack vectors before producing code.
- Onboard security engineers to unfamiliar codebases. The structured, multi-stage output provides a security-focused overview of architecture, data flows, threats, and vulnerabilities without manually reading the entire codebase.
- Triage and prioritize remediation. The final stages produce a P0-P3 remediation roadmap ranked by risk reduction vs. implementation effort, giving engineering teams a ready-made security backlog.
How It Works
โโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ
โ CLI โโโโโ>โ Orchestrator โโโโโ>โ AI Coding Agent โ
โ โ โ โ โ โ
โ threatsmith โ โ - Framework packs โ โ Claude Code / โ
โ /path/to/repo โ โ - Stage sequencing โ โ Codex โ
โ --framework โ โ - Prompt assembly โ โ โ
โ --engine โ โ - Context passing โ โ - Code nav โ
โ โ โ - Scanner detection โ โ - File I/O โ
โ โ โ - Output validation โ โ - Shell exec โ
โโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโ โ - Reasoning โ
โโโโโโโโโโโโโโโโโโโโ
ThreatSmith runs a sequential pipeline defined by the selected framework pack. Each stage executes as a fresh agent session but receives all prior stage outputs as structured context. This mirrors how a security engineer works through a methodology: read the prior findings, then produce the next deliverable.
Currently supports Claude Code (--engine claude-code) and Codex (--engine codex). Adding a new engine requires implementing a single method: execute(prompt, working_directory) -> exit_code.
4QF + STRIDE stages
| Stage | Name | Output |
|---|---|---|
| 1 | System Model | Application architecture, data flows, trust boundaries (Mermaid DFDs) |
| 2 | Threat Identification | Systematic STRIDE analysis per component, OWASP cross-referencing |
| 3 | Mitigations | Countermeasures, gap analysis, priority ranking (P0-P3) |
| 4 | Validation | Coverage verification, accepted risks, review cadence |
| 5 | Report | Executive summary consolidating all stage outputs |
PASTA stages
| Stage | Name | Output |
|---|---|---|
| 1 | Define Objectives | Business objectives, data sensitivity, compliance requirements |
| 2 | Define Technical Scope | Technology stack, dependencies, supply chain, deployment |
| 3 | Application Decomposition | Architecture, data flow diagrams (Mermaid), trust boundaries |
| 4 | Threat Analysis | STRIDE analysis, attack scenarios, OWASP cross-referencing |
| 5 | Vulnerability Analysis | Scanner results, CVSS scoring, CWE/CVE enumeration |
| 6 | Attack Modeling | Attack trees (Mermaid), MITRE ATT&CK mapping, exploit paths |
| 7 | Risk and Impact Analysis | Risk qualification, countermeasures, P0-P3 remediation roadmap |
| 8 | Report | Executive summary consolidating all stage outputs |
Context Accumulation
Each stage builds on all prior stages. Stage N receives the outputs of stages 1 through N-1, injected as structured XML-delimited sections in the prompt. This accumulated context directs the agent's analysis, reducing blind codebase exploration and improving output quality.
Installation
Prerequisites
- Python 3.12+
- One of the supported AI coding agents installed and authenticated:
Claude Codefor the claude-code engineCodexfor the codex engine
Install
# With pip
pip install threatsmith
# With uv
uv tool install threatsmith
# With pipx (no virtual environment needed)
pipx install threatsmith
# With uvx (no virtual environment needed)
uvx install threatsmith
Quick Start
threatsmith /path/to/your/repo
This runs the full 4QF + STRIDE pipeline using Claude Code (the default engine) and writes all deliverables to threatmodel/ inside the target repository.
To use a different framework, engine, or provide objectives to guide the analysis:
threatsmith /path/to/your/repo \
--framework pasta \
--engine codex \
--business-objectives "Protect user PII, meet GDPR requirements" \
--security-objectives "Prevent data exfiltration" \
-v
To see all available frameworks:
threatsmith --list-frameworks
Scanner Integration
ThreatSmith automatically detects security scanners on your system before running the pipeline. When a scanner is found, stage-specific instructions are injected into the appropriate stage prompt so the agent knows to run it and incorporate the results. Which stage receives scanner instructions depends on the framework (Stage 2 for 4QF + STRIDE, Stage 5 for PASTA).
| Scanner | Purpose | Detection |
|---|---|---|
| Semgrep | Static analysis patterns | which semgrep |
| Trivy | Dependency CVE scanning | which trivy |
| Gitleaks | Secret/credential detection | which gitleaks |
Scanners that are not detected are omitted from the prompt entirely. Scanner availability is recorded in metadata.json for traceability.
Output Structure
All deliverables are written to a threatmodel/ directory (configurable via --output-dir) at the target repository root. The files produced depend on the selected framework.
4QF + STRIDE
threatmodel/
metadata.json # Run metadata (engine, framework, commit, scanners, timestamp)
01-system-model.md # Stage 1: Architecture, data flows, trust boundaries
02-threat-identification.md # Stage 2: STRIDE analysis and threat inventory
03-mitigations.md # Stage 3: Countermeasures and gap analysis
04-validation.md # Stage 4: Coverage verification and accepted risks
05-report.md # Executive summary
PASTA
threatmodel/
metadata.json # Run metadata (engine, framework, commit, scanners, timestamp)
01-objectives.md # Stage 1: Business objectives and data sensitivity
02-technical-scope.md # Stage 2: Technology stack and dependencies
03-application-decomposition.md # Stage 3: Architecture, DFDs, trust boundaries
04-threat-analysis.md # Stage 4: Threat identification and attack scenarios
05-vulnerability-analysis.md # Stage 5: Vulnerability findings and CVSS scoring
06-attack-modeling.md # Stage 6: Attack trees and exploitation paths
07-risk-and-impact-analysis.md # Stage 7: Risk qualification and remediation roadmap
08-report.md # Executive summary
Individual stage files are preserved alongside the consolidated report. This supports selective consumption (a developer fixing an auth issue only needs the threat and mitigation stages), debuggability (re-examine a single stage's output), and granular review by security teams.
CLI Reference
threatsmith <path> [OPTIONS]
| Parameter | Type | Default | Description |
|---|---|---|---|
path |
positional | required | Path to the target repository |
--framework |
string | stride-4q |
Threat modeling framework (stride-4q or pasta) |
--engine |
string | claude-code |
AI engine to use (claude-code or codex) |
--business-objectives |
string | โ | Business objectives to guide the analysis |
--security-objectives |
string | โ | Security objectives to guide the analysis |
--output-dir |
string | threatmodel/ |
Output directory for deliverables (relative to target repo) |
--rerun-stage |
integer | โ | Re-run a single stage using existing prior stage outputs |
--list-frameworks |
flag | off | List all available frameworks and exit |
-v / --verbose |
flag | off | Enable verbose (debug-level) logging |
Roadmap
- Additional frameworks. LINDDUN Pro (privacy-focused) and MAESTRO (AI/ML-focused) framework packs.
- Batch mode. Process multiple repositories from a file list (
--repos repos.txt) with configurable parallelism (--parallel N). - Auto-PR creation. Automatically commit the
threatmodel/directory, push a branch, and open a pull request viaghCLI after analysis completes. - Incremental updates. Use
git diffagainst the commit hash inmetadata.jsonto selectively re-run only the stages affected by code changes. - Stage re-run. Re-run a specific stage (e.g.,
--rerun-stage 5) using existing prior stage outputs without re-running the entire pipeline. - Resume from stage. Resume a failed or interrupted pipeline run from the stage where it stopped.
- CI/CD integration. GitHub Action and GitLab CI templates for automated threat modeling on pull requests.
- Threat model diff. Compare two threat model runs and surface what changed between them.
License
MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file threatsmith-0.3.0.tar.gz.
File metadata
- Download URL: threatsmith-0.3.0.tar.gz
- Upload date:
- Size: 150.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.0 {"installer":{"name":"uv","version":"0.11.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
75fda3818cd588bd6f19109f1202d3eba7235ec880a4cac4727bedb732980464
|
|
| MD5 |
b638506ac1a0b3c342967f22a062e0b6
|
|
| BLAKE2b-256 |
88155966f97aa9e4356dd3749f769c377a120126d9a7add45afad617b6e26945
|
File details
Details for the file threatsmith-0.3.0-py3-none-any.whl.
File metadata
- Download URL: threatsmith-0.3.0-py3-none-any.whl
- Upload date:
- Size: 92.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.0 {"installer":{"name":"uv","version":"0.11.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
01ec7624f4daadb74e9e3f52583990454e2b5542e9e3ad9aa2d15c47e704925e
|
|
| MD5 |
7821bf7c740009e2dc3602dcb3c6019a
|
|
| BLAKE2b-256 |
1a88fec5e62ff3a789b4a929f1e120e65aa430598ffb5ff4572da6111c2089b3
|