It can. The pip documentation says that by default pip involves running arbitrary code from distributions. Building from a source distribution executes build code on your machine. Passing the only-binary option for all packages tells pip to refuse source distributions and install prebuilt wheels only, which removes that step.
Two kinds of files
A Python package version is usually published as one or more files:
- Wheel: A prebuilt archive. Installing it unpacks files into place.
- Source distribution: The source plus metadata. To install it, pip has to build it first, and building runs code defined by the package.
The pip secure installs page lists two ways to tighten this: hash-checking mode, and disallowing source distributions with the only-binary option set to all.
What the only-binary setting gives you
pip install --only-binary :all: -r requirements.txt
With that flag, a package that publishes no wheel for your platform will fail to install instead of building. You see the failure, and you can decide whether to trust the build.
The benefit is concrete. A malicious or compromised source distribution cannot run its build code during your install, because pip will not build it.
What it does not remove
Wheels do not run code at install in the same way, but their contents still run when you import the package. A wheel can contain malicious Python. The option narrows one path. It does not make a package safe.
What it breaks
Some legitimate packages publish only source, or lack a wheel for your Python version or processor. Common reactions are to switch the flag off for everything. A better approach:
- Identify the package that failed.
- Check whether a newer version publishes wheels for your platform.
- If not, decide whether you trust that source, read the build configuration and build it once in a throwaway environment or container.
- Record the exception in the repository.
Combine with hashes and virtual environments
The documentation pairs the only-binary option with hash-checking mode, and they complement each other: hashes detect change, binary only avoids source builds. Add a virtual environment per project, so a bad install lands in a folder you can delete, not in your system Python.
A configuration tip
pip reads configuration files at three levels, and environment variables can override them, per its configuration documentation. Putting the setting in your user configuration protects every project without remembering the flag. Check how your teammates and CI configure theirs, so results match.
A safe place to build the exceptions
When you must build from source, do it in a throwaway container or virtual machine with no mounted credentials and no access to your home directory. Build the wheel there, copy out only the wheel, and install that. You get the compatibility you needed without running unreviewed build code beside your keys.
If you want a quick look at what your projects actually resolve, Safeguard offers SBOM and dependency scanning, and there is a free scan at gold.safeguard.sh/scan.
Quick check
Is a wheel always safe to install?
No. It avoids a build step, but its code still runs when imported. Safe origin does not mean safe code.
What happens if a package has no wheel and I use only-binary?
pip fails to install it rather than building from source. You then decide whether to trust and build it manually.
Sources
Last reviewed: 19 October 2026.