Bandit: a free security linter that reads your Python code for common mistakes before you ship
Bandit is a free, open-source command-line tool that scans Python code for common security issues by reading its structure and running tests on it. Based on the official README, documentation and release notes, not tested by us: what it does, what it checks, its limits and what we could not confirm.
Free and open source (Apache License 2.0)
Founders and small teams who write Python, often with an AI assistant, and want a quick free check for risky patterns such as hardcoded passwords, shell commands built from text and unsafe file loading before each release.
It only reads Python and only finds the patterns its tests cover, so a clean report is not proof of safety. It also reports things that are fine in your case, so each finding needs a human decision.
← All tool profilesNo. 15 / 21
In one sentence
Bandit is a scanner for your own Python code. It reads each file, builds a map of its structure (an AST, short for abstract syntax tree) and runs a set of tests against it, then prints a report of anything that looks like a security problem. This kind of check is called static analysisStatic analysis (SAST) A tool that reads your source code without running it and flags patterns that often lead to security bugs, such as unsafe queries or hard-coded secrets. Tap again to open the glossary: it reads the code without running it.
Who it is for
People who write Python, especially with help from AI assistants, and want a cheap automatic review of what was generated before it ships. It is a command-line tool, so you need to be comfortable typing commands. It does not replace a human review, and it does not look at other languages.
What the documentation says
Everything below comes from the project's README, its documentation and its releases page, which we read on 23 November 2026.
- What it is: the README calls it a security linter from PyCQA and says it was originally developed within the OpenStack Security Project and later moved to PyCQA. The documentation says it processes each file, builds an AST and runs the appropriate plugins against its nodes, then generates a report.
- Licence: the README says free software under the Apache licence, and the documentation names the Apache License 2.0.
- Install:
pip install bandit, ideally inside a virtual environment. Optional extras add TOML configuration support (bandit[toml]), the baseline tool (bandit[baseline]) and SARIF output (bandit[sarif]). The README also lists a container image on ghcr.io, signed with sigstore cosign. - First scan:
bandit -r path/to/your/codescans a folder and everything inside it. - Only show the serious ones:
--severity-level=highor the short form-lllreports only high-severity issues, and-n 3shows three lines of context. - Profiles and input: a profile such as
ShellInjectionruns only the tests listed in it, and Bandit can read code from standard input. - Baseline: you can save a report in JSON format and pass it back with
-b, so that known issues you have accepted are ignored. The documentation gives a cleartext password in a unit test as an example. - Configuration: a
.banditfile (INI) is read when you scan with-r; a YAML or TOML file, such as the[tool.bandit]section ofpyproject.toml, is passed with-c. You can exclude folders and choose which tests to run or skip. - Silencing a finding: add
# nosecto the line, or name the tests, for example# nosec B602, B607. The documentation recommends adding a comment that explains why the line was excluded. - Python versions: the FAQ says Bandit reads code with Python's own parser, so you should run it under the Python version your project targets. The release notes say version 1.9.0 added support for Python 3.14 and dropped the end-of-life Python 3.9.
What it checks
The documentation lists its tests as plugins with IDs. The groups are: B1xx miscellaneous, B2xx framework misconfigurationMisconfiguration A setting left wrong or at its default that exposes something, such as a storage bucket open to everyone or an admin page with no login. Tap again to open the glossary, B3xx and B4xx risky calls and imports, B5xx cryptography, B6xx injection and B7xx cross-site scripting. A few of them, as the documentation names them:
- B105: a hardcoded password string. B106 and B107 cover passwords in function calls and default values.
- B602: a subprocess call with
shell=True. B608: SQL built as text. - B506:
yaml.load, which can build arbitrary objects. - B501: a web request that does not verify the certificate.
- B113: a web request without a timeout.
- B201: Flask running with debug on.
- B701: Jinja2 with autoescape off.
- B101: use of
assert. - B614 and B615, which concern AI work:
torch.loadand unsafe downloads from Hugging Face. The release notes say B614 was narrowed totorch.loadin 1.9.3 and a B615 false alarm was fixed in 1.9.4.
The good
- Free, open source and installed with one
pipcommand. - One command scans a whole project and you can filter by severity.
- Tests cover typical mistakes in code that AI assistants write: secretsSecret (API key, token, password) Any piece of text that proves to a service that you are allowed in, such as an API key, a database password or an access token. Tap again to open the glossary in the code, shell commands, unsafe loading of data and models, disabled certificate checks.
- Baselines and
# nosecwith a test ID let a team accept what it has reviewed without silencing everything. - It can run in a build pipeline or as a pre-commit hook; the documentation shows a pre-commit setup.
- The project publishes regular releases.
The limits it admits
- It is a Python-only tool: the documentation describes finding common security issues in Python code.
- It works on the code's structure, so the Python version you run it with matters: code written for a different version may fail to parse, as the FAQ explains.
- The documentation itself says a flagged line may be a false positive or acceptable for another reason, which is why
# nosecand baselines exist. - The documentation does not give a count of how many issues it finds on a real project, or a false-alarm rate.
When not to use it
- If you think a clean report means your code is safe. It only finds what its tests cover.
- For other languages. Pair it with a scanner that reads them.
- To find vulnerable libraries. From what we read, Bandit checks your own code; for dependencies see our OSV-Scanner profile.
- As your only check. Review, tests and dependency scanning still matter.
What it costs you
Time more than money. The documentation gives no estimate of setup time. The real work is deciding what to fix and what to accept, tuning out false alarms with a configuration file or # nosec, and adding the scan to your build. We have not measured any of this.
Typical setup mistakes
- Scanning once and forgetting. Run it on every change, ideally in your build pipeline.
- Silencing without a reason. A bare
# nosechides every issue on that line, including ones added later. Name the test and write why. - Skipping whole test IDs to make the report shorter. You lose the check everywhere.
- Running it under a different Python version than your project. Code can fail to parse.
- Treating the report as a score. A short report is not a safe app.
- Pasting secrets into an online tool or an AI chat to "check" a finding. Keep keys out of prompts.
How to check that it works
Once you try it, in a test folder with fake data: write a small file with a risky line on purpose, such as a fake password in a variable and a subprocess call with shell=True, run Bandit on the folder and confirm that each risky line is reported. If one is not, find out why before trusting the tool. Never test with real keys or on a production system. We have not run this ourselves yet.
Where to start
A short path, from the official getting-started page (not tested by us):
- Create a virtual environment and activate it, then install with
pip install bandit. - Scan a project folder with
bandit -r path/to/your/code. - Narrow it to the serious findings with
bandit -r path/to/your/code --severity-level=high. - For each finding, fix it or accept it with a
# nosecthat names the test and explains why. - When you are happy, add it to your build or to a pre-commit hook.
Official documentation for everything else: httpsHTTPS The secure version of the web address protocol: it encrypts what travels between a visitor and your site and checks that the site is the real one. Tap again to open the glossary://bandit.readthedocs.io/en/latest/
What we could not confirm
We did not install or run Bandit, so we cannot say how many findings or false alarms it gives on a real project, how fast it is on a large codebase, or how it behaves on Windows. We did not read the page on the report formats, the list of blacklisted calls and imports or the continuous-integration page, and the date of version 1.9.4 was not in the text we read. We do not know how it compares with other scanners.
Related
Sources
- PyCQA/bandit: README on GitHub (read 23 Nov 2026) (opens in a new tab)
- Bandit documentation: getting started (read 23 Nov 2026) (opens in a new tab)
- Bandit documentation: configuration (read 23 Nov 2026) (opens in a new tab)
- Bandit documentation: test plugins (read 23 Nov 2026) (opens in a new tab)
- Bandit documentation: frequently asked questions (read 23 Nov 2026) (opens in a new tab)
- PyCQA/bandit: releases page (read 23 Nov 2026) (opens in a new tab)
Follow us
New profiles and security news: YouTube (@safet2ship) and Instagram (@safet2ship).
More tool profiles
Same topic first, then the newest.
BLA (Blind LLM Agents)
A free shield that makes it costly for an AI agent to reverse-engineer your software, not impossible
Best forDevelopers and small teams who ship a client-side app, an Electron app, a WASM module or a local model and worry that an AI agent can read it and copy it in minutes.
ZAP
A free scanner that looks for security holes in a web app you are building
Best forA founder or developer who wants to check their own web app or API for common holes before launch, on a test copy.
Lynis
A free audit that checks a Linux server's security settings and tells you what to fix
Best forAnyone who runs their own Linux server and wants a checklist of settings to tighten, without a network scan.
Our own free checks
Small tools we built: they run in your browser and store nothing.
Website security check
Paste your site address and get a grade, a plain-language report and copy-paste fixes for HTTPS, security headers and cookies.
Keys-in-your-code check
Find API keys and secrets that your app exposes in public files. Built for apps made with AI.
Metadata check
See what hidden data your photos, PDFs and Office files carry (author, software, dates, GPS location) before you share them. Runs in your browser.
Exposure check
A self-check of what your company leaks in public (files, email records, accounts, repositories), with links to the tool for each point.