Back to blog

Blog

How to Automate Threat Modeling (Without Faking It)

How to automate threat modeling for real: what to hand to tools, what stays human, threat modeling as code with pytm and Threagile, and CI/CD triggers.

how to automate threat modelingUpdated 11/25/2026Shafi Khan

How to Automate Threat Modeling (Without Faking It)

To automate threat modeling, put the system model somewhere a machine can read it (a diagram, a YAML file or Python code), let a rule engine generate candidate threats from it, and re-run that analysis every time the architecture changes. Humans still own the two hardest calls: which threats actually matter, and whether the mitigations are good enough.

That's the whole answer. The rest of this post is the how: which steps tools handle well, which tools fit which teams, working threat modeling as code examples, and how to wire it into CI/CD without drowning everyone in findings.

Why manual threat modeling quietly dies

Every team has one. The threat model from the project kickoff. Lovingly drawn, reviewed once, exported to PDF, and never opened again while the system grew three new services, a queue and a "temporary" public endpoint.

Manual threat modeling doesn't fail because people don't care. It fails because:

  • It's a workshop, not a habit. Getting architects, developers and security into one room is expensive, so it happens once per project instead of once per meaningful change.
  • The model drifts from reality. The diagram describes the design you approved, not the system you shipped.
  • Threat lists start from zero every time. Someone re-derives "the database could be read by an attacker" from scratch, again.
  • Nobody knows when to redo it. Without clear triggers, "we should revisit the threat model" lives forever in the backlog.

The OWASP Threat Modeling Cheat Sheet is blunt about the fix: threat modeling should ideally happen early in the SDLC, the model should be maintained and refined alongside the system, and it's beneficial to use processes and tools that simplify and automate it. Automation is how you get from "workshop" to "habit."

→ Pressure-test your current design with the free STRIDE Threat Checklist

How to automate threat modeling: what tools do well vs. what stays human

The cleanest way to scope this is the four questions the cheat sheet borrows from the Threat Modeling Manifesto: What are we working on? What can go wrong? What are we going to do about it? Did we do a good enough job? Map each one to what automation can genuinely take off your plate.

QuestionWhat automation does wellWhat stays human
What are we working on?Generate the model from diagrams, code, IaC or YAML; render data flow diagrams; keep it versionedConfirming the model matches reality and that trust boundaries are in the right place
What can go wrong?Rule-based candidate threats (e.g. STRIDE per element), consistent coverage, no forgotten categoriesBusiness-specific abuse cases, chained attacks, "what would actually hurt us"
What are we going to do about it?Suggested mitigations, linking findings to tickets, tracking statusChoosing to mitigate, eliminate, transfer or accept; owning the risk decision
Did we do a good enough job?Re-running on every change, diffing findings, reports for auditsJudging residual risk and signing off

Notice the pattern. Tools are great at coverage and repetition. People are needed for context and accountability. Any tool that claims to remove humans from risk acceptance is selling vibes, not security.

→ See how Threat Analyzer runs the repetitive half on your architecture diagram

Automated threat modeling tools: the three main approaches

There are dozens of products in this space, but they cluster into three approaches. Pick the one that matches where your architecture already lives.

1. Diagram-first tools with a rule engine

You draw a data flow diagram; the tool generates threats per element.

  • OWASP Threat Dragon is free, open-source and cross-platform, running as a web or desktop app. Its project page says it supports STRIDE, LINDDUN, CIA, DIE and PLOT4ai and implements a rule engine to auto-generate threats and their mitigations.
  • Microsoft Threat Modeling Tool is part of the Microsoft Security Development Lifecycle (SDL). Microsoft's documentation describes guidance and feedback while drawing the model, plus STRIDE-per-element guided analysis of threats and mitigations.

Best for: teams that think visually and want a low barrier to entry. The catch: the diagram is a separate artefact, so someone still has to keep it current.

2. Threat modeling as code

You describe the system in a text file; the tool generates diagrams, threats and reports.

  • OWASP pytm is "a Pythonic framework for threat modeling." You define actors, servers, data stores, data flows and boundaries in Python, and pytm outputs DFDs (Graphviz dot), sequence diagrams (PlantUML) and reports. Threats come from a rules file where each threat has a condition evaluated against your elements.
  • Threagile is an MIT-licensed, open-source toolkit for agile threat modeling. You model the architecture as YAML, and it checks its standard risk rules (plus any custom rules) against the model, producing a PDF report, Excel and JSON risk exports and data flow diagrams. It runs as a Docker image.

Best for: platform and DevSecOps teams who want the threat model reviewed in pull requests. The catch: the YAML or Python model is yet another description of the system that can drift from the real one.

3. Architecture-first analysis

Instead of maintaining a separate threat model, you run threat analysis on the architecture diagram the team already uses for design reviews. This is the approach behind Architecto's Threat Analyzer: it applies STRIDE-driven threat modeling to architecture diagrams, starting from a generated design, a saved architecture or a known pattern, and produces threat findings and mitigation guidance that feed the security review.

Best for: teams whose architecture diagram is already the source of truth for reviews. The catch: you still need a human to own risk decisions (see above, forever).

ApproachExamplesModel lives inStrengthWatch out for
Diagram-first rule engineOWASP Threat Dragon, Microsoft Threat Modeling ToolA dedicated threat model fileVisual, approachableSeparate diagram to maintain
Threat modeling as codeOWASP pytm, ThreagilePython or YAML in GitPR reviews, CI/CD, diffableModel drift, learning curve
Architecture-first analysisArchitecto Threat AnalyzerThe architecture diagramOne source of truth for design and securityDiagram must reflect the real system

None of these is "the best automated threat modeling tool" in general. The best one is the one your team will actually keep up to date.

→ Compare diagram-as-code and visual workflows before you pick a tool

Threat modeling as code: a pytm example you can run

Here's a minimal pytm model for a public checkout API in front of a Postgres database. Two trust boundaries, one actor, two data flows.

#!/usr/bin/env python3
from pytm import TM, Actor, Boundary, Dataflow, Datastore, Server

tm = TM("Checkout API")
tm.description = "Public checkout API backed by a PostgreSQL orders database"
tm.isOrdered = True

internet = Boundary("Internet")
private_vpc = Boundary("Private VPC")

customer = Actor("Customer")
customer.inBoundary = internet

api = Server("Checkout API")
api.inBoundary = private_vpc

orders_db = Datastore("Orders DB")
orders_db.inBoundary = private_vpc

checkout = Dataflow(customer, api, "POST /checkout")
checkout.protocol = "HTTPS"
checkout.dstPort = 443

write_order = Dataflow(api, orders_db, "Insert order")
write_order.protocol = "PostgreSQL"
write_order.dstPort = 5432

tm.process()

Then generate the outputs straight from the file:

# Data flow diagram (needs Graphviz)
python3 tm.py --dfd | dot -Tpng -o dfd.png

# List the threat rules pytm knows about
python3 tm.py --list

# Findings report from a markdown template (pytm ships docs/basic_template.md)
python3 tm.py --report docs/basic_template.md | pandoc -f markdown -t html > report.html

Why this slaps compared with a slide-deck threat model:

  • The model is diffable. Adding a new data flow to a third-party payment provider shows up in the pull request, right where reviewers are already looking.
  • Findings are reproducible. Same model plus same rules equals same candidate threats, so you can compare runs over time.
  • The richer you make the model (data classification, encryption flags, authentication properties), the sharper the rule matches get.

One honest caveat: the pytm README notes that its threats file contains strings that run through Python's eval(), so treat custom rule files like code and review them as such.

If you want to see what a complete, human-reviewed result should look like before you automate it, walk through our STRIDE threat model example for a web application, which goes threat by threat with mitigations.

→ Grab the threat model template guide to structure your findings

Threat modeling in CI/CD: when to re-run (and when not to panic)

Automation pays off when the model re-runs on change. Here's a GitHub Actions job that runs Threagile whenever the threat model YAML changes in a pull request and uploads the reports as an artifact. The docker run arguments follow the Threagile README.

name: threat-model
on:
  pull_request:
    paths:
      - "threagile.yaml"

jobs:
  threagile:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Run Threagile
        run: |
          mkdir -p threat-model-output
          docker run --rm \
            -v "$PWD":/app/work \
            threagile/threagile \
            --verbose \
            --model /app/work/threagile.yaml \
            --output /app/work/threat-model-output

      - name: Upload reports
        uses: actions/upload-artifact@v4
        with:
          name: threat-model
          path: threat-model-output/

Two rollout tips that save you from alert fatigue:

  1. Start in report-only mode. Don't fail builds on the first run, because every existing risk will show up at once. Publish the report, triage the baseline, then decide what (if anything) should block a merge.
  2. Review the diff, not the pile. The useful signal in a PR is "this change introduced new risks," not "here are all 40 risks again."

When to update a threat model: the trigger checklist

Not every commit needs a threat review. These changes do:

  • A new internet-facing endpoint, listener or public bucket
  • A new trust boundary, or a component moving across one (e.g. private subnet to public)
  • A new data store, or an existing one starting to hold sensitive data
  • A new third-party integration, webhook or SaaS dependency
  • Any change to authentication, authorization, session handling or secrets flow
  • A new deployment region, account or tenant isolation model
  • An incident or pen-test finding that the current model didn't predict

If your pipeline can detect these (path filters on IaC, API specs or the architecture file), you've automated the most neglected part of threat modeling: knowing when to do it.

→ Check exposed ports and CIDRs fast with the Security Group Rule Visualizer

Can AI do threat modeling?

Short answer: AI can draft, it can't sign off.

Where AI-assisted threat modeling genuinely helps:

  • Turning messy context into a model. Generating a structured architecture from a prompt, a repository or IaC is much faster than drawing it by hand, and that model is the input every threat technique needs.
  • Consistent first-pass coverage. Walking every element through every STRIDE category is tedious for humans and easy to skip. A tool doesn't get bored at element 37.
  • Explaining threats in context. A finding that points at the actual component on the diagram gets fixed; a row in a spreadsheet gets ignored.

Where it falls short:

  • It doesn't know your business. A threat that's catastrophic for a payments platform might be acceptable for an internal wiki.
  • It can be confidently wrong about the system if the diagram is wrong. Garbage model in, garbage threats out.
  • Risk acceptance is an accountability decision, and accountability needs a name attached to it.

The practical setup: let AI generate the architecture with Architect AI, run automated threat modeling from the architecture diagram with Threat Analyzer, then have a human review trust boundaries using the trust boundaries explainer as the reference. Layer Security Posture on top when you also need to check network boundaries, service exposure and zero-trust expectations.

→ Generate the architecture first, then threat-model it, with Architect AI

A four-step rollout plan

You don't need a six-month DevSecOps program. You need four boring, repeatable steps.

  1. Pick the source of truth. Decide where the system model lives: the architecture diagram, a pytm file or a Threagile YAML. One place. If you maintain two, one of them is already stale.
  2. Baseline one critical system. Run the tool, triage every candidate threat with the owning team, and record the decision (mitigate, eliminate, transfer or accept) and the owner.
  3. Add triggers. Wire the checklist above into PR templates or pipeline path filters, so changes that move trust boundaries automatically request a threat review.
  4. Close the loop. Re-run after the change ships and confirm the finding disappeared or the accepted risk is documented. That's the "did we do a good enough job?" question, answered with evidence instead of vibes.

Then expand to the next system. Coverage grows one service at a time, and each baseline makes the next one cheaper.

→ Turn your review into a reusable checklist with the Architecture Review Checklist Builder

Key takeaways

  • Automate the repetition, not the judgment. Tools build the model, generate candidate threats and re-run on change; humans decide what matters and accept risk.
  • There are three main approaches: diagram-first rule engines (Threat Dragon, Microsoft Threat Modeling Tool), threat modeling as code (pytm, Threagile) and architecture-first analysis (Architecto Threat Analyzer).
  • The best tool is the one tied to your real source of truth. A perfect threat model of an outdated diagram is still wrong.
  • Triggers beat schedules. Re-run when exposure, trust boundaries, sensitive data, third parties or auth change.
  • Start report-only in CI/CD and review new risks per change, not the whole backlog every time.

→ Run STRIDE-driven analysis on your next design with Threat Analyzer

FAQ

Can threat modeling be fully automated?

No. Tools can automate the repetitive parts: building the model from diagrams, code or YAML, generating candidate threats from rules such as STRIDE per element, producing reports and re-running the analysis when the architecture changes. Deciding which threats matter for your business, accepting or rejecting risk, and judging whether mitigations are good enough still needs people who understand the system.

What are the best automated threat modeling tools?

It depends on how your team works. OWASP Threat Dragon is a free, open-source diagramming tool with a rule engine that generates threats. Microsoft's Threat Modeling Tool offers STRIDE-per-element guided analysis on a data flow diagram. OWASP pytm (Python) and Threagile (YAML) are threat modeling as code tools that fit Git and CI/CD. Architecture platforms such as Architecto apply STRIDE-driven analysis directly to the architecture diagram you already maintain.

What is threat modeling as code?

Threat modeling as code means describing the system (actors, servers, data stores, data flows and trust boundaries) in a text format such as Python or YAML that lives in version control. A tool then generates diagrams, candidate threats and reports from that file, so the threat model can be reviewed in pull requests and re-run in a pipeline like any other code.

When should a threat model be updated?

Whenever a change alters what an attacker could reach: a new public endpoint, a new or moved trust boundary, a new data store holding sensitive data, a new third-party integration, or a change to authentication or authorization. The OWASP Threat Modeling Cheat Sheet recommends maintaining the model alongside the system rather than treating it as a one-time document.

→ Keep the STRIDE Threat Checklist handy for your next review

Stop shipping threat models that expire on day one

The goal isn't a prettier threat model. It's a threat model that's still true next quarter. Put the model where your architecture already lives, let automation handle coverage and re-runs, and keep humans on the decisions that need judgment.

Architecto lets you generate the architecture, run STRIDE-driven threat analysis on it and carry the findings into security reviews, all from the same diagram.

→ Start free and threat-model your first architecture today

FAQ

Questions readers ask before they act on this page.

Can threat modeling be fully automated?

No. Tools can automate the repetitive parts: building the model from diagrams, code or YAML, generating candidate threats from rules such as STRIDE per element, producing reports and re-running the analysis when the architecture changes. Deciding which threats matter for your business, accepting or rejecting risk, and judging whether mitigations are good enough still needs people who understand the system.

What are the best automated threat modeling tools?

It depends on how your team works. OWASP Threat Dragon is a free, open-source diagramming tool with a rule engine that generates threats. Microsoft's Threat Modeling Tool offers STRIDE-per-element guided analysis on a data flow diagram. OWASP pytm (Python) and Threagile (YAML) are threat modeling as code tools that fit Git and CI/CD. Architecture platforms such as Architecto apply STRIDE-driven analysis directly to the architecture diagram you already maintain.

What is threat modeling as code?

Threat modeling as code means describing the system (actors, servers, data stores, data flows and trust boundaries) in a text format such as Python or YAML that lives in version control. A tool then generates diagrams, candidate threats and reports from that file, so the threat model can be reviewed in pull requests and re-run in a pipeline like any other code.

When should a threat model be updated?

Whenever a change alters what an attacker could reach: a new public endpoint, a new or moved trust boundary, a new data store holding sensitive data, a new third-party integration, or a change to authentication or authorization. The OWASP Threat Modeling Cheat Sheet recommends maintaining the model alongside the system rather than treating it as a one-time document.

Related reading

Keep moving through the architecture workflow.

Free tool

STRIDE Threat Checklist

Walk through spoofing, tampering, repudiation, information disclosure, denial of service, and elevation risks using a deterministic system model.

threat modeling checkliststride templatesecurity review checklist

Free tool

Architecture Review Checklist Builder

Build repeatable review packets for cloud architectures, migrations, data systems, and internal platforms without relying on static spreadsheets.

system design review checklistarchitecture governance checklistdesign review template

Free tool

Security Group Rule Visualizer

See inbound and outbound exposure patterns across security group rules before a review turns into line-by-line spreadsheet work.

aws security group analyzerfirewall rule visualizersecurity group matrix

Guide

threat models checklist for Security Architecture

threat models checklist for Security Architecture with technical review guidance, practical artifacts, and a workflow path into diagrams, documentation, and architecture governance.

security architecturethreat modelsapplication security architecture

Guide

What trust boundaries means in Security Architecture

What trust boundaries means in Security Architecture with technical review guidance, practical artifacts, and a workflow path into diagrams, documentation, and architecture governance.

security architecturetrust boundariesapplication security architecture

Comparison

Best Structurizr alternative for architecture review

Best Structurizr alternative for architecture review with a workflow-first comparison across diagrams, architecture review, technical documentation, and code-adjacent implementation evidence.

structurizr alternativearchitecto vs structurizrarchitecture review workflow alternative
How to Automate Threat Modeling (Without Faking It) | Architecto