pkgscan.dev · Documentation
How to check a PyPI package for malicious code
Python packaging gives a package several ways to run code before your program does: setup.py, a build backend, or a wheel that executes on import. pkgscan scans the artifact you point it at and reports each engine separately — but static analysis has hard limits on Python. Here is what it can and cannot tell you.
Updated 2026-11-05
Where PyPI malware hides
- Install-time code.
setup.py,setup.cfghooks, or a PEP 517 build backend that runs when pip builds an sdist. Modern pip can use build isolation, but the build step still runs. - Import-time code. A wheel whose top-level module performs network calls or reads credentials on first import.
- Encoded payloads.
exec(base64.b64decode(...)),marshalblobs, or a tiny loader that fetches a second stage from a paste site or a raw IP. - Environment harvesting. Reads of
os.environ,~/.aws,~/.ssh, cloud metadata endpoints, or CI tokens, followed by an outbound request. - Typosquats and dependency confusion. Names one edit away from a popular package, or a private package name published publicly with a higher version.
Scan a PyPI package with pkgscan
Open pkgscan.dev and search for the package, or use the PURL URL directly: /pkg/pypi/{name}@{version}. pkgscan resolves the version on PyPI, downloads the distributable, and runs every eligible engine. You can also upload a .whl or .tar.gz if the artifact is not public, and a SHA-256 lookup works for artifacts that were scanned before.
# Public report for a version curl -s https://www.pkgscan.dev/api/pkg/pypi/[email protected] # Start a fresh scan curl -s -X POST https://www.pkgscan.dev/api/scan/from-generic-purl \ -H "Authorization: Bearer pkg_YOUR_KEY" \ -H "Content-Type: application/json" \ -d '{"purl":"pkg:pypi/[email protected]"}'
Which engines run on a PyPI artifact
| Engine | What it contributes |
|---|---|
| Argus | Content analysis of the uploaded or downloaded artifact |
| GuardDog | PyPI rule set for install hooks, obfuscation, exfiltration, and credential access |
| OSV and deps.dev | Published advisories and malware advisories matched to the PURL |
| Grype | Known CVEs from the advisory databases baked at build time |
Inspect an sdist or wheel yourself
# Download without installing dependencies pip download --no-deps --no-binary :all: -d ./pkgs example-package==1.2.3 # List the archive contents python3 -m zipfile -l ./pkgs/example_package-1.2.3-py3-none-any.whl # grep for the usual first-stage markers grep -RnE 'exec\(|b64decode|marshal\.loads|urlopen|requests\.post|os\.environ' ./pkgs
For an sdist, read setup.py and pyproject.toml before anything else. For a wheel, list the files and open the module that runs on import. If the package ships only an sdist and the code is generated during the build, read the build backend as well.
Limits specific to Python packages
- A wheel can bundle compiled extensions; the behaviour is in the binary, not in readable Python.
- Packages can be deleted or yanked from PyPI after an incident, so the version you are investigating may no longer be downloadable. Keep the hash of what you audit.
- pkgscan scans the package itself, not the resolved dependency graph of your project.
- Version ranges in advisories are evaluated by the vulnerability engines; a fixed version reported clean still needs your own patch check.
Related: checking npm packages, detection methods and verdict semantics.
Check a package or file now: scan it on pkgscan.dev.