loading
loading
Static Code Analysis
AST-based security checks for Python source.
overview
bandit reads Python source, builds an AST, and runs security plugins against the nodes. That catches hardcoded passwords, shell injection, weak crypto, and unsafe deserialization that a text grep misses or over-reports.
Tune the run: -ll or -lll set a severity floor, --skip drops noisy test IDs, --baseline keeps only new findings, and -f chooses csv, json, xml, html, and other report shapes.
Trickest provides bandit as a managed Static Code Analysis node. Feed a FILE or FOLDER of Python source, often with --recursive; it writes FILE and FOLDER findings for triage or merge with dynamic scanner output.
source github.com/PyCQA/bandit
use cases
Point bandit at a source folder with --recursive and let its plugins surface injection, weak crypto, and hardcoded secrets across the whole codebase.
Compare against a baseline JSON report with --baseline so previously accepted issues stay quiet and the run flags only fresh problems.
Raise the severity floor with -ll or -lll and drop noisy plugins with --skip so a run returns the high-signal findings worth acting on.
Emit JSON or XML with -f and route bandit findings into the same table and reporting flow as dynamic scanner output for one risk view.
reference
| Name | Type | Flag | Description |
|---|---|---|---|
| targets-folder | FOLDER | targets | Source folder to scan. |
| targets-file | FILE | targets | Source file(s) to scan. |
| recursive-target | FOLDER | --recursive | Find and process files in subdirectories. |
| output-format | STRING | -f | Output format: csv, custom, html, json, screen, txt, xml, or yaml. |
| level-medium | STRING | -ll | Report only issues at MEDIUM severity or higher (-l low, -lll high). |
| baseline | FILE | --baseline | Path of a baseline JSON report to compare against. |
| skip-id | STRING | --skip | Comma-separated list of test IDs to skip. |
| exit-zero | BOOLEAN | --exit-zero | Exit with 0 even when results are found. |
Showing key inputs. bandit exposes 23 inputs in total.
| Name | Type | Flag | Description |
|---|---|---|---|
| debug | BOOLEAN | -d | Turn on debug mode. |
| quiet | BOOLEAN | -q | Only show output in the case of an error. |
| profile | STRING | --profile | Profile to use (defaults to executing all tests). |
| skip-id | STRING | --skip | Comma-separated list of test IDs to skip. |
| test-id | STRING | --tests | Comma-separated list of test IDs to run. |
| verbose | BOOLEAN | --verbose | Output extra information like excluded and included files. |
| baseline | FILE | --baseline | Path of a baseline report to compare against (only JSON-formatted files are accepted). |
| ini-file | FILE | --ini | Path to a .bandit file that supplies command line arguments. |
| aggregate | STRING | --aggregate | Aggregate output by vulnerability (default) or by filename. |
| exit-zero | BOOLEAN | --exit-zero | Exit with 0, even when results are found. |
| level-low | STRING | -l | Report only issues at LOW severity or higher. |
| confidence | BOOLEAN | --confidence | Report only issues at a given confidence level or higher. |
| level-high | STRING | -lll | Report only issues at HIGH severity or higher. |
| config-file | FILE | --configfile | Optional config file to use for selecting plugins and overriding defaults. |
| ignore-nosec | BOOLEAN | --ignore-nosec | Do not skip lines with # nosec comments. |
| level-medium | STRING | -ll | Report only issues at MEDIUM severity or higher. |
| msg-template | STRING | --msg-template | Specify output message template (only usable when output-format is set to custom). |
| number-lines | STRING | --number | Maximum number of code lines to output for each issue. |
| targets-file | FILE | targets | Source file(s) to scan. |
| exclude-paths | STRING | --exclude | Comma-separated list of paths (glob patterns supported) to exclude from the scan, in addition to the config file excludes (default: .svn,CVS,.bzr,.hg,.git,__pycache__,.tox,.eggs,*.egg). |
| output-format | STRING | -f | Output format: csv, custom, html, json, screen, txt, xml, or yaml. |
| targets-folder | FOLDER | targets | Source folder to scan. |
| recursive-target | FOLDER | --recursive | Find and process files in subdirectories. |
example
# recursively scan a source tree, medium severity and up, JSON reportbandit -r ./src -ll -f json -o findings.jsonRun started:2026-07-14 09:12:03Test results:>> Issue: [B105:hardcoded_password_string] Possible hardcoded password: 'changeme' Severity: Low Confidence: Medium Location: ./src/config.py:14:14>> Issue: [B602:subprocess_popen_with_shell_equals_true] subprocess call with shell=True identified. Severity: High Confidence: High Location: ./src/tasks.py:52:8Code scanned: 1284 lines across 9 files, 2 issues (1 High, 1 Low)guidance
Use bandit when the target is Python source, not a running app. It reasons about code; dynamic scanners test the deployed service, so pair both for coverage. For many languages with one engine, reach for semgrep instead.
Pattern-based static analysis across many languages. bandit is Python-only and ships Python-specific plugins out of the box.
Equivalent security linter for Go. Same role, different language.
Security scanner for Ruby web apps. Sibling tool for a different stack.
faq
related
Detect hardcoded secrets in git repos and plain directories.
Go AST security scanner for credentials, crypto, and injection.
Regex scan of JavaScript for API keys, tokens, JWTs, and similar client-side secrets.
Static analysis with rules that look like the code they match.
Hunt leaked credentials and verify which still work.
Static review of Ruby source for security issues, CVEs, and OWASP risks.
Python source feeds bandit, which builds an AST, runs its security plugins, and writes the findings as a queryable output.
Facts on this page come from the live Trickest tool library.