Static Code Analysis
Find shell injection in a Python folder
bandit is the Python Code Quality Authority's security linter that parses Python source into an abstract syntax tree and runs it through a battery of plugin tests to flag issues such as SQL injection, weak cryptography, and unsafe deserialization.
installpip install banditdocker pull ghcr.io/pycqa/bandit/bandit
Python · Apache-2.0 license
Free plan: 1 user, 3 execution slots, no card.
overview
What bandit does
Bandit reads a connected folder of Python files, parses each file into an AST, and writes a JSON report of plugin hits.
A Managed-fleet smoke on a two-line script that calls subprocess with shell=True returned B602, the shell-injection check, in that JSON report.
Connect the folder that holds the .py files. A bare text file is not scanned as Python.
source github.com/PyCQA/bandit
image quay.io/trickest/bandit:1.9.4
use cases
bandit use cases
Scan application source
Point Bandit at the folder that contains the Python modules you ship.
Catch shell invocation
Surface subprocess calls that pass shell=True before that code runs.
Hand JSON to triage
Keep the plugin id, filename, and issue text in one report for a later node.
reference
bandit inputs and flags
| Name | Type | Flag | Description |
|---|---|---|---|
| source | FOLDER | --source | Folder of Python source to scan. |
Showing key inputs. bandit exposes 1 inputs in total.
example
bandit command examples
bandit --source ./src{"test_id": "B602", "issue_severity": "LOW", "filename": "app.py", "issue_text": "subprocess call with shell=True seems safe, but may be changed in the future, consider rewriting without shell"}guidance
bandit vs alternatives
Use Bandit when the artifact is Python source. Use Semgrep for multi-language rules, and OSV-Scanner when the question is a lockfile advisory.
| Tool | Pick it when |
|---|---|
| semgrep-scan | Runs custom rules across more languages than Python. |
| osv-scanner | Matches lockfiles to known vulnerability advisories. |
| gosec | Looks for security problems in Go source. |
faq
bandit FAQ
related
More Static Code Analysis tools
gitleaks
Detect hardcoded secrets in git repos and plain directories.
gosec
Go AST security scanner for credentials, crypto, and injection.
guarddog
A package coordinate in, indicator hits out.
malcontent-scan
A package coordinate in, behavior findings out.
osv-malicious
A package coordinate in, malware advisory rows out.
osv-scanner
A lockfile in, advisory rows out.
Run bandit yourself
A folder containing app.py with subprocess.call and shell=True produced a JSON report that included B602.
Facts on this page come from the live Trickest tool library.