# Add cargo-deny to a Rust Workspace

Yes. An agent writes a deny.toml for your Cargo workspace, tunes it until cargo deny check passes on your lockfile, adds the CI job and opens a pull request.

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

## What the agent does

The agent clones the workspace into its own cloud sandbox and reads what it already checks before it adds a policy file. In a workspace like rust-lang/mdBook, the root `Cargo.toml` lists members `.`, `crates/*`, `examples/remove-emphasis/mdbook-remove-emphasis` and `guide/guide-helper`, sets `edition = "2024"`, `rust-version = "1.88.0"` and the workspace license `MPL-2.0`, and `Cargo.lock` holds 273 `[[package]]` entries with no git sources. `.github/workflows/main.yml` already runs a test matrix across stable, beta, nightly and an `msrv` row pinned to `1.88.0`, plus `rustfmt`, `typos`, `clippy` with `-D warnings`, `cargo doc`, `cargo-semver-checks` v0.51.0 and an `audit` job that installs `cargo-audit` with `cargo install --locked` and runs `cargo audit`; a `success` gate job lists every other job in `needs`. `CONTRIBUTING.md` documents `cargo audit`. There is no `deny.toml`, and `update-dependencies.yml` bumps dependencies on the first of each month with `cargo-edit`.

The agent installs `cargo-deny`, runs `cargo deny list` to see which licenses the resolved graph actually carries, and writes `deny.toml` from that output rather than from a template. `[licenses]` gets an `allow` list of exactly the identifiers found, which must cover the workspace's own `MPL-2.0` and the compound expression `crates/mdbook-html/Cargo.toml` declares, `MPL-2.0 AND Apache-2.0 AND BSD-3-Clause AND CC-BY-4.0 AND MIT AND OFL-1.1`, because the vendored front-end assets ship under those terms. `[advisories]` points at the RustSec database the `audit` job already consults and sets `yanked = "deny"`. `[sources]` allows crates.io only, which matches the lockfile. `[bans]` starts with `multiple-versions = "warn"`, because the lock resolves two or three versions of 21 crates today, among them `syn` at 1, 2 and 3, `rand` at 0.8 and 0.9, `html5ever` at 0.26 and 0.39 and `getrandom` at three versions, and each would need a `skip` entry with a reason before the setting could be `deny`.

It then runs `cargo deny check` and reads every failure. A license the allow list missed becomes either an entry or a `[[licenses.exceptions]]` for that one crate; a crate whose license file `cargo-deny` cannot parse gets a `[[licenses.clarify]]` with the file's hash; an advisory that cannot be acted on yet is listed under `ignore` with its id and a comment. The agent repeats until the check passes with the lockfile unchanged, since changing dependencies to satisfy a new policy is a separate decision for the maintainers.

Finally it adds a `deny` job to `main.yml` using the pinned `cargo-deny` action, adds `deny` to the `success` job's `needs` list so branch protection sees it, and extends the `cargo audit` section of `CONTRIBUTING.md` with how to run the check locally and how to add an exception. It leaves the existing `audit` job in place and says in the pull request that the two overlap on advisories, so maintainers can drop one later. `cargo fmt --check`, `cargo clippy --workspace --all-targets --no-deps -- -D warnings` and `cargo test --workspace --locked` run unchanged before the push.

## Start it with one API call

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

```json
{
  "agent": "claude",
  "input": "Add cargo-deny to this Rust workspace and open a pull request. Read Cargo.toml, Cargo.lock, every member crate's Cargo.toml, .github/workflows/main.yml and CONTRIBUTING.md first. Install cargo-deny, run cargo deny list, and write deny.toml with a licenses allow list built from the licenses actually present, advisories from the RustSec database with yanked crates denied, sources limited to crates.io, and bans with multiple-versions set to warn. Run cargo deny check and fix every failure with the narrowest exception, each with a comment saying why, without changing Cargo.lock. Add a deny job to the CI workflow with a pinned cargo-deny action and include it in the success gate. Document the check in CONTRIBUTING.md next to cargo audit. Run cargo fmt --check, clippy and the test suite, and put the cargo deny check output in the pull request description.",
  "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 `deny.toml`, edits `.github/workflows/main.yml` to add the `deny` job and list it under `success.needs`, and extends `CONTRIBUTING.md`. `Cargo.lock` and every `Cargo.toml` are untouched. The description pastes the final `cargo deny check` summary, the license identifiers the allow list contains, and every exception with its reason.

The run's record keeps the first failing `cargo deny check` output as well as the passing one, so a reviewer can see which crates needed a clarification or an exception and judge each one rather than trust that the file was tuned sensibly.

Before merging, a reviewer checks that the allow list contains no license the project would not accept just because a crate happened to carry it, that each `multiple-versions` duplicate is one they expect, and that the pinned action version matches the `cargo-deny` version used in the sandbox so the CI result equals the local one.

## Run it on every Cargo.lock change

Once `deny.toml` is merged, the `deny` job runs on every pull request. An automation in the Project with a `github` trigger on `pull_request.opened` starts one run per pull request a maintainer opens, with the pull request as its context; the trigger has no path filter, so the prompt tells the run to stop unless the diff touches `Cargo.lock`. The monthly bump from `update-dependencies.yml` is opened by a bot, and a bot sender fires no trigger, so for that one a maintainer starts the run with `POST /o/{org}/sessions` and `https://github.com/<owner>/<repo>/pull/<n>` in `resources`. The run reads the `cargo deny check` failure on the new graph, proposes the narrowest change to `deny.toml` or names the dependency to pin back, and posts it as a review comment on that pull request, as the prompt says.

From your own server, the same work is one `POST /o/{org}/sessions` per repository, with the repository in `resources`; the key's `webhook_url` posts `run.completed` with `data.session_url` when each turn ends.

## Why run it on Rush?

A `deny.toml` written without running the check is a guess about 273 crates' licenses, and the first CI run usually shows the guess was wrong. The sandbox has the toolchain, installs `cargo-deny`, runs the check against the real lockfile as many times as it takes, and keeps every attempt, so the file in the pull request has already passed.

The policy also has to fit the workflow that exists: the `success` gate, the pinned action style, the monthly dependency bump. One run reads all of it and returns a job that belongs in that file, and the same prompt runs across every Rust repository in the org at once, each in its own sandbox with its own lockfile.

## Frequently asked questions

### Does cargo-deny replace cargo-audit?

It covers the same RustSec advisories, plus licenses, duplicate versions and sources. The agent keeps the existing `audit` job and says so in the pull request, so maintainers can remove it in a follow-up once the `deny` job has run for a while. Nothing in the workflow is deleted by the run.

### Will it change my dependencies to make the check pass?

No. `Cargo.lock` stays as it is. The agent satisfies the check with the narrowest entry in `deny.toml`, each with a comment, and lists in the description the duplicates and advisories a maintainer might want to resolve by upgrading instead.

### How are the duplicate versions handled?

With `multiple-versions = "warn"` at first. The lockfile resolves two or three versions of 21 crates, including `syn` at 1, 2 and 3, and turning that into an error on day one would block every pull request. The description lists them so the setting can become `deny` with `skip` entries once the tree is trimmed.

### What if a crate's license cannot be detected?

`cargo-deny` reports it, and the agent adds a `[[licenses.clarify]]` entry naming the crate, the SPDX expression and the hash of the license file it read, so the clarification breaks when the file changes. The pull request shows each one and the file it was read from.

## More Rust jobs

- [Add Test Coverage Reporting to Rust CI](https://getrush.ai/run/add-coverage-to-ci/rust/)
- [Add Criterion Benchmarks to a Rust Workspace](https://getrush.ai/run/add-criterion-benchmarks/rust/)
- [Add Fuzz Tests to a Rust Project](https://getrush.ai/run/add-fuzz-tests/rust/)

## The same job on other stacks

- [Add cargo-deny to a Rust CLI's CI](https://getrush.ai/run/add-cargo-deny/rust-cli/)
- [Add cargo-deny to a Rust Library Workspace](https://getrush.ai/run/add-cargo-deny/rust-library/)
- [Add cargo-deny to a Tokio Project](https://getrush.ai/run/add-cargo-deny/tokio/)

## 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/)
