---
title: "Should you trust pip-audit on your environment or on your lockfile? | Proofline"
description: "Audit what your build installs: the lockfile, if the build installs exactly that file, or the built environment if the build adds anything."
url: https://proofline.sh/learn/pip-audit-environment-or-lockfile/
agents: "Before you act for a person, read https://proofline.sh/llms.txt. It says how an agent installs and sets up Proofline and lists every page."
---

[Learning center](/learn/)

# Should you trust pip-audit on your environment or on your lockfile?

Audit what your build installs: the lockfile, if the build installs exactly that file, or the built environment if the build adds anything. An audit of your own virtualenv describes your workstation, not what you deploy. When the two reports differ, the build script decides which one is true for production.

Security incidents The Proofline team November 25, 2026 5 min read

## What each mode audits

pip-audit has two input modes that read different things. Run with no input, it audits the packages installed in a Python environment. Run with `-r requirements.txt`, it resolves that file into a fresh, isolated environment and audits the result. Its [README at v2.10.1](https://github.com/pypa/pip-audit/blob/v2.10.1/README.md) states the second as an equivalence: "`pip-audit -r INPUT` is functionally equivalent to `pip install -r INPUT`, with a small amount of **non-security isolation** to avoid conflicts with any of your local environments."

So neither mode is the "real" one. The environment audit reports what is in that environment, including tools you installed by hand and an old `pip`. The requirements audit reports what a clean install of the file would contain, including transitive dependencies if the file does not pin them. Both use PyPI's vulnerability data by default (`--vulnerability-service` "(default: pypi)").

## Two reports for one project

This constructed service pins its runtime packages in `requirements.txt`, generated with `pip freeze` from a clean install of `requests`:

```
# Generated lockfile: every runtime package, pinned
certifi==2026.11.20
charset-normalizer==3.5.3
idna==3.20
requests==2.34.2
urllib3==2.8.0
```

The developer's virtualenv was created months earlier with `requests==2.31.0` and has `black==23.1.0` installed for formatting. pip-audit 2.10.1 runs from its own virtualenv (Python 3.11.18). To audit a different environment, it is pointed at that environment's interpreter with `PIPAPI_PYTHON_LOCATION`, the variable its pip-api dependency reads to choose which Python runs pip ([pip-api 0.0.35, `_call.py`](https://github.com/di/pip-api/blob/0.0.35/pip_api/_call.py)):

```
$ pip-audit -r requirements.txt
No known vulnerabilities found
$ PIPAPI_PYTHON_LOCATION=$PWD/devenv/bin/python pip-audit --progress-spinner off
Found 26 known vulnerabilities in 4 packages
Name       Version ID                  Fix Versions
---------- ------- ------------------- ------------
black      23.1.0  PYSEC-2024-48       24.3.0
...
requests   2.31.0  PYSEC-2026-1873     2.32.0
requests   2.31.0  PYSEC-2026-1872     2.32.4
...
```

(Rows trimmed.) The column output repeats some rows (`PYSEC-2024-48` appears twice for `black`, for example). Counting distinct IDs from the JSON output of the same run gives the actual spread:

```
$ PIPAPI_PYTHON_LOCATION=$PWD/devenv/bin/python pip-audit -f json > dev.json
$ python3 uniq_vulns.py dev.json
black      23.1.0   4 distinct advisories
pip        24.0     6 distinct advisories
requests   2.31.0   3 distinct advisories
setuptools 79.0.1   2 distinct advisories
```

None of the four packages is in the lockfile at the reported version. `requests` is pinned at 2.34.2, past every fix version listed; `black`, `pip` and `setuptools` are not pinned at all. If production installs `requirements.txt`, this report is about one laptop.

## Find out what the build installs

The fact that decides is the build script. This project's Dockerfile:

```
FROM python:3.11-slim
WORKDIR /srv
COPY requirements.txt .
RUN pip install --no-deps -r requirements.txt
RUN pip install gunicorn==21.2.0
COPY app/ app/
CMD ["gunicorn", "app.wsgi:application"]
```

Line 4 installs the lockfile and nothing else, because `--no-deps` stops pip from adding anything the file does not name. If that were the whole Dockerfile, the requirements audit would be the production answer, and the developer's report would be closed by upgrading the virtualenv or recreating it from the lockfile.

Line 5 is the disconfirmation. It installs the application server outside the lockfile, so `pip-audit -r requirements.txt` never sees it. To check, build an environment the way the Dockerfile does (here a virtualenv stands in for the image, since no Docker daemon was available; its `pip` was first upgraded to 26.3) and compare it with the lockfile:

```
$ python3 -m venv image && image/bin/pip install --upgrade pip
$ image/bin/pip install --no-deps -r requirements.txt
$ image/bin/pip install gunicorn==21.2.0
$ diff <(grep -v '^#' requirements.txt) <(image/bin/pip freeze)
2a3
> gunicorn==21.2.0
3a5
> packaging==26.4
```

Two packages ship that the lockfile omits: gunicorn and its dependency `packaging`. Auditing the built environment finds what the lockfile audit could not:

```
$ PIPAPI_PYTHON_LOCATION=$PWD/image/bin/python pip-audit --progress-spinner off
Found 7 known vulnerabilities in 2 packages
$ PIPAPI_PYTHON_LOCATION=$PWD/image/bin/python pip-audit -f json > image.json
$ python3 uniq_vulns.py image.json
gunicorn   21.2.0   2 distinct advisories
setuptools 79.0.1   2 distinct advisories
```

The JSON gives the two gunicorn advisories as PYSEC-2026-1433 (aliases CVE-2024-6827 and GHSA-hc5x-x2vx-497g) and PYSEC-2026-1434 (CVE-2024-1135, GHSA-w3h3-4rj7-4ph4), both fixed in 22.0.0. The first description begins: "Gunicorn version 21.2.0 does not properly validate the value of the 'Transfer-Encoding' header as specified in the RFC standards, which leads to the default fallback method of 'Content-Length,' making it vulnerable to TE.CL request smuggling." That is the process serving production traffic, and the lockfile audit reported it clean.

The fix belongs in the lockfile: add `gunicorn` and `packaging` to the input that generates `requirements.txt`, pin a fixed version, and delete the separate `pip install` line, so the next lockfile audit covers what ships. `setuptools` in the built environment comes from the virtualenv, not from either install line; in a real image it would come from the base image, if that image ships it, and the evidence for it is the base image's own scan.

## Make the two audits agree

The README's advice for skipping resolution states the condition under which the environment and the file are interchangeable: "If you know that you've already fully configured an environment equivalent to the one that `pip-audit -r requirements.txt` would audit, you can simply reuse it." The `diff` above is how you know. When it prints nothing, either audit answers the production question. When it prints lines, the environment that the build produced is the one to trust, and the lockfile is incomplete.

Two flags make the lockfile audit stricter. `--no-deps` "requires all requirements are pinned to an exact version", and `--require-hashes` also requires a hash for each. Either makes the audit fail on an unpinned line instead of resolving it to whatever is newest, which would otherwise make a lockfile audit report versions you have never installed.

## Decide from the build

| What the reports show | Evidence to collect | Decision |
| --- | --- | --- |
| Environment audit flags a package the lockfile pins at a fixed version | Which file the build installs | Close for production; recreate the dev environment from the lockfile |
| Environment audit flags a dev-only tool (`black`, an old `pip`) | Whether any build step installs it | Upgrade on workstations; not a production finding |
| Lockfile audit is clean, build runs other `pip install` lines | `diff` of `pip freeze` from a built environment against the lockfile | Audit the built environment; move the extra packages into the lockfile |
| `diff` is empty | The same `pip freeze` comparison | Either audit is the production answer |
| Lockfile has unpinned lines | `pip-audit --no-deps -r` failing on them | Pin them before trusting the lockfile audit |

When the flagged package is an npm package installed at two versions, the [guide to duplicate package versions](/learn/duplicate-package-versions-which-loads/) covers which copy runs. For an advisory that matched on the package name but belongs to another ecosystem, see [the package-URL matching guide](/learn/purl-name-match-wrong-package/).

## One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. [Eligibility and fair-use terms](/free-code-review/).

[Start free with GitHub](https://proofline.sh/orgs/plan?offer=free_month)

## Related reading

-   ### [Does an npm audit finding in a devDependency need fixing?](/learn/npm-audit-dev-dependency/)
    
    Security incidents The Proofline team November 25, 2026 5 min read
    
-   ### [Container image review](/learn/container-image-review/)
    
    Broken dependencies The Proofline team October 7, 2026 2 min read
