Safeguard
Security Guides•

What does SAST for Python find, and how do you start?

SAST for Python parses code into a syntax tree and flags risky calls such as eval, shell use and weak crypto. What it finds, misses and how to begin.

Safeguard Security Team
3 min read

SAST for Python reads your source without running it and flags risky constructs: dynamic code execution, shell commands built from strings, unsafe deserialization, weak hashing and hardcoded passwords. It will not understand your business rules, so treat it as a filter for known bad patterns.

How it works

The documentation for Bandit, a widely used open source Python security linter, describes the approach: parse each file into an abstract syntax tree, run plugins against the nodes, then generate a report. Most Python SAST tools follow that shape, with deeper ones adding data flow tracking from inputs to dangerous calls.

What it typically finds

PatternWhy it is risky
eval and exec on variable inputCode injection
subprocess with shell enabled and built stringsCommand injection
pickle on untrusted dataCode execution on load
yaml load without safe loaderObject construction from input
String built SQLSQL injection
MD5 or SHA1 for security useWeak hashing
Literal passwords and tokensCredential exposure

Each of these has a safer alternative. See pickle with untrusted data and safe_load versus load.

What it misses

  • Logic flaws such as missing authorization checks.
  • Vulnerabilities inside dependencies. That is software composition analysis, a different scan.
  • Runtime configuration, such as debug mode left on in production.
  • Dynamic features like heavy metaprogramming, where static reasoning is limited.

Steps to start

  1. Run the scanner on the whole repository once and record the baseline count.
  2. Exclude tests and generated code, but only after reading what is excluded.
  3. Triage the highest severity and highest confidence findings first.
  4. Fix or suppress with a written reason. Avoid blanket ignores.
  5. Run in CI on pull requests and fail only on new high severity findings, so the team is not buried by old debt.
  6. Pair it with dependency scanning, because most Python projects import far more code than they write.

How Safeguard helps

Safeguard offers dependency scanning and SBOMs, reachability analysis, and autonomous remediation with fix pull requests, which is off by default with every category on Manual. The free scan is the easiest first step.

Try it yourself

Click through it at your own pace, or open it full screen.

Open a finding and look at the code path from input to the risky call.

Quick check

Does SAST find vulnerable Python packages?

No. It analyzes your code. Package vulnerabilities need dependency scanning.

Should I fail the build on every finding?

Not at first. Fail on new high severity findings and work down the old backlog separately.

Sources

  • Bandit documentation, home page (fetched 19 October 2026): AST based approach.

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.