# Add pip-audit to a Python Project's CI

Yes. An agent adds pip-audit to your pinned tooling, runs it against the installed environment, wires it into the test workflow with a weekly run and opens a PR.

[Run this on Rush](https://cloud.getrush.ai/run/add-pip-audit-to-ci/python/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent clones the project into its own cloud sandbox and reads how dependencies are declared before adding a tool. In a library like encode/httpx, `pyproject.toml` builds with `hatchling`, requires Python `>=3.9`, and lists four runtime dependencies, `certifi`, `httpcore==1.*`, `anyio` and `idna`, plus optional extras for `brotli`, `cli`, `http2`, `socks` and `zstd`. `requirements.txt` is the development environment: it starts with `-e .[brotli,cli,http2,socks,zstd]` and then pins every tool exactly, `mkdocs==1.6.1`, `build==1.3.0`, `twine==6.1.0`, `coverage[toml]==7.10.6`, `cryptography==45.0.7`, `mypy==1.17.1`, `pytest==8.4.1`, `ruff==0.12.11`, `trio==0.31.0`, `uvicorn==0.35.0` and the rest, under a comment that explains the policy: tooling is pinned because the project controls that environment, package dependencies are not because the tests must pass against their latest versions.

It then reads `.github/workflows/test-suite.yml`, which runs on pushes to `master` and on pull requests to `master` and `version-*` branches across Python `3.9` to `3.13`, calling `scripts/install`, `scripts/check`, `scripts/build`, `scripts/test` and `scripts/coverage` in turn. `scripts/install` does `pip install -r requirements.txt` straight into the runner's interpreter when `GITHUB_ACTIONS` is set and into a `venv/` otherwise; `scripts/check` runs `ruff format --diff`, `mypy` and `ruff check`; `scripts/coverage` fails under 100 percent. `.github/dependabot.yml` groups all pip updates into one monthly pull request, which means a pin with a published advisory can wait up to a month unless something checks sooner, and `publish.yml` uploads to PyPI on tags with `twine`.

The agent adds `pip-audit`, pinned exactly like the other tools, to `requirements.txt`, and a `scripts/audit` script in the same style as its neighbours, with the `venv/bin/` prefix logic, that runs `pip-audit --strict --desc` against the installed environment. Auditing the environment rather than the file is deliberate: the file's first line is an editable install with extras, so the environment is the only place where the resolved versions of `certifi`, `anyio` and the extras exist. The script also passes `--skip-editable` so the project itself, which has no published version in that environment, is not reported as unknown.

In `test-suite.yml` it adds one step, `Audit dependencies`, after `Install dependencies`, guarded so it runs on a single Python version of the matrix, since the pinned tools resolve the same way on each and five identical audits add nothing. It adds a `schedule` entry to the workflow's `on:` block so the audit also runs weekly against the unchanged pins, which is how an advisory published after the last push gets noticed before Dependabot's monthly pull request. It runs `scripts/install` and `scripts/audit` in the sandbox first; when the audit reports a vulnerable pin, the agent bumps that one pin to the fixed version in the same pull request and reruns `scripts/check` and `scripts/test` to show the bump is safe, and when a finding has no fixed release it adds `--ignore-vuln` with the advisory id and a dated comment rather than leaving the check red.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Add pip-audit to this Python project. Read pyproject.toml, requirements.txt, every file under scripts/ and every workflow under .github/workflows first. Add pip-audit to requirements.txt pinned exactly like the other tools, and write scripts/audit in the same style as the existing scripts, auditing the installed environment with --strict and --desc and skipping the editable install of the project itself. Add one Audit dependencies step to the test workflow after the install step, running on a single Python version of the matrix, and a weekly schedule trigger on the workflow. Run the install and the audit in the sandbox; if it reports a vulnerable pin with a fixed release, bump that pin and rerun the lint and test scripts; if a finding has no fix, ignore it by advisory id with a dated comment. Open a pull request that quotes the audit output.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request that adds `scripts/audit`, one line to `requirements.txt` for the tool itself, one step and one `schedule` trigger in `test-suite.yml`, and, when the audit found a vulnerable pin, the bump of that pin. The description quotes the audit output, names each advisory by id with the pin it affects, and says which were fixed by a bump and which are ignored with a reason.

The run's record keeps the install, the audit and, after any bump, the `scripts/check` and `scripts/test` runs, so a reviewer can see that `ruff`, `mypy` and the test suite still pass at the new pin without re-running them. The `publish.yml` workflow and `pyproject.toml` are unchanged.

Before merging, a reviewer checks the matrix guard picks the Python version they want to own the audit, decides whether the weekly schedule should also notify somewhere, and reads any `--ignore-vuln` line to confirm the advisory really has no fixed release for a pin the project keeps.

## Run it on every Monday morning

With the step in CI, the weekly scheduled run turns red when a new advisory lands, but a red scheduled run is only useful if someone acts on it. An automation with a `schedule` trigger, `cron` set to Monday morning in your `timezone`, starts one run a week that installs the pins, runs `scripts/audit` and, when it reports a vulnerable pin with a fixed release, bumps the pin, reruns `scripts/check` and `scripts/test` and opens a pull request that quotes the advisory. A clean audit ends the run with a one-line note and no pull request.

A bump that breaks `mypy` or the tests ends the run `needs_review` with the failing output in its trajectory, so the person who picks it up on Monday starts from the error rather than from the advisory. Dependabot's monthly grouped pull request keeps doing the routine upgrades; this run exists for the ones that cannot wait a month.

## Why run it on Rush?

The useful part of a dependency audit is the first run and the policy that follows it, not the YAML. The agent runs the real tool against the real installed environment in its own sandbox, reads the project's own pinning policy from the comment at the top of `requirements.txt`, and writes a script and a step that fit the five that already exist, with the audit output in the record so the pull request's claims are checkable.

For an organisation with many Python repositories, the same request returns one pull request per project, each auditing that project's own environment and each quoting its own findings. Projects whose pins are clean get a small diff; projects with an advisory get the bump and the test run that proves it is safe, in the same change.

## Frequently asked questions

### Why audit the installed environment instead of requirements.txt?

Because the file's first line is `-e .[brotli,cli,http2,socks,zstd]`: the runtime dependencies and extras are resolved at install time, not pinned in the file. Auditing after `scripts/install` covers the pinned tools and the resolved runtime packages together.

### Will a vulnerability fail every pull request?

Yes, on the one matrix entry that runs the audit, which is the point. The weekly schedule means the failure usually appears first on a scheduled run rather than on someone's unrelated pull request, and the automation above turns that scheduled failure into a pull request with the fix.

### What if the advisory has no fixed release?

The agent adds `--ignore-vuln` with the advisory id to `scripts/audit` and a comment with the date and the reason, so the check stays green and the ignore is visible in review. Removing the ignore when a fix ships is a one-line follow-up.

### Does this replace Dependabot?

No. `.github/dependabot.yml` keeps opening its monthly grouped pull request for routine updates. The audit catches the advisory that arrives in between, which the monthly cadence would otherwise leave open for up to a month.

## More Python jobs

- [Add Pre-commit Hooks to a Python Project](https://getrush.ai/run/add-pre-commit-hooks/python/)
- [Add towncrier Changelog Fragments to a Python Package](https://getrush.ai/run/add-towncrier-changelog/python/)
- [Add mypy Type Checking to a Python Project's CI](https://getrush.ai/run/add-type-checking/python/)

## More jobs like this: Upgrade dependencies weekly

- [Set Up Renovate for an Ansible Role](https://getrush.ai/run/add-renovate/ansible/)
- [Add Renovate to Keep Docker Compose Image Tags Current](https://getrush.ai/run/add-renovate/docker-compose/)
- [Set Up Renovate for a Temporal TypeScript Monorepo](https://getrush.ai/run/add-renovate/temporal/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
