# Add cargo-deny to a Tokio Project

Yes. An agent runs cargo deny on your Tokio project's lockfile, writes a deny.toml that passes, adds the check to CI with advisories non-blocking, and opens a PR.

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

## What the agent does

The agent reads the dependency graph before it writes policy for it. In a Tokio project laid out like tokio-rs/mini-redis, `Cargo.toml` is a single crate on edition 2018 with `tokio` on the `full` feature set, `tokio-stream`, `bytes`, `clap` with `derive`, `atoi`, `async-stream`, `tracing` and `tracing-subscriber`, plus an `otel` feature that pulls in `opentelemetry`, `tracing-opentelemetry`, `opentelemetry-aws` and `opentelemetry-otlp` as optional dependencies. `Cargo.lock` is committed and resolves that into `[[package]]` entries that include two versions each of `syn`, `socket2`, `regex-automata` and `regex-syntax`, which is what a `bans` check with `multiple-versions` set to deny will trip on first. `.github/workflows/ci.yml` builds and tests with and without the `otel` feature on Ubuntu, macOS and Windows and runs `cargo fmt --all --check`; there is no clippy, no audit, no Dependabot and no `deny.toml`.

So the agent starts from the tool's own report rather than a template. It installs cargo-deny in its sandbox, runs `cargo deny init` to get the default `deny.toml`, and runs `cargo deny check` with `--all-features` so the `otel` graph is included, the same arguments the GitHub action defaults to. The `licenses` section is where the real work is: in the current config format everything is denied unless it is in `allow`, so the agent writes the `allow` list from the license expressions the check reports across the graph, keeps `confidence-threshold` at its default, and adds a `clarify` entry only for a crate whose license file the tool cannot classify, naming the file and its hash as the format requires. Because the project is MIT, the agent flags in the pull request any license in the list that a reviewer may not want and leaves the decision there.

For `bans` it sets `multiple-versions` to `warn` rather than `deny`, since the four duplicated crates come from transitive dependencies the project does not control, and lists them in the description so a later `cargo update` can be judged against them; `wildcards` stays at the default. `advisories` keeps the RustSec database with no ignores, and `sources` allows only crates.io, since the lockfile has no git sources. It runs `cargo deny check` again until all four checks pass.

Then it adds `.github/workflows/deny.yml` using `EmbarkStudios/cargo-deny-action@v2`, in the shape the action's README recommends: a matrix with `advisories` as one entry and `bans licenses sources` as the other, `command: check ${{ matrix.checks }}`, and `continue-on-error` on the advisories entry so a newly published advisory shows up without blocking every unrelated pull request. The job runs on pull requests and on pushes to the default branch, next to the existing `CI` workflow rather than inside it, so the three-OS build matrix is untouched. The pull request carries the full output of the final `cargo deny check` and the one that ran on the empty template, so the reviewer sees what the config had to say and why.

## Start it with one API call

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

```json
{
  "agent": "claude",
  "input": "Add cargo-deny to this Tokio project and open a pull request. Read Cargo.toml, Cargo.lock, README.md and .github/workflows/ci.yml first. Install cargo-deny in the sandbox, run cargo deny init, then run cargo deny check --all-features on the template config and keep its output. Write deny.toml from what it reports: an allow list of the licenses actually in the graph, a clarify entry only where the tool cannot classify a license file, multiple-versions set to warn with the duplicated crates listed in the pull request, the RustSec advisory database with no ignores, and crates.io as the only allowed source. Run the check again until all four checks pass. Add .github/workflows/deny.yml with EmbarkStudios/cargo-deny-action@v2 in a matrix that keeps advisories on continue-on-error, running on pull requests and pushes to the default branch. Do not change ci.yml or upgrade any crate. Put both check outputs in the pull request.",
  "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

The pull request adds `deny.toml` and `.github/workflows/deny.yml`. Its description pastes the `cargo deny check --all-features` output on the untouched template and on the final file, lists every license in the `allow` list and the crate that brought it in, names the four crates present at two versions, and explains why advisories are on `continue-on-error`.

The new `deny` workflow runs on the pull request itself, so a reviewer sees both matrix entries pass on a GitHub runner before merge, beside the unchanged `CI` matrix. The run's record keeps the cargo-deny install and every check the agent ran.

Before merging, a reviewer decides whether any license in the `allow` list should be removed and the crate replaced, whether `multiple-versions` should become `deny` once the duplicates are gone, and whether the advisories entry should block merges after the team has lived with it for a while.

## Run it on every Cargo.lock change

Once `deny.toml` is merged, the check runs on every pull request, and the ones that change the answer are the ones that touch `Cargo.lock`. An automation on the Project with a `github` trigger on `pull_request.opened` and `pull_request.synchronize` and the prompt "if this pull request changes Cargo.lock, run cargo deny check and, when it fails, comment with the narrowest deny.toml change that passes or the crate to hold back" reviews each of them; the trigger has no path filter, so the prompt tells the run to stop when the lockfile is untouched. Automation runs are read-only and comment only.

A team that wants the advisories entry to stay green runs this prompt weekly from an automation with a `schedule` trigger, in the Project that holds the repository. A run that finds a new advisory opens a pull request that either bumps the affected crate or adds an `ignore` with the advisory id and a reason; a run that finds nothing ends with no pull request and says so. An automation has its own `max_runs_per_hour` cap, separate from any API key.

## Why run it on Rush?

A `deny.toml` written from a template is a guess about every license and duplicate in the lockfile, and the first CI run shows where the guess was wrong. The agent runs the check against the real graph with the real feature set in its own sandbox first, writes the config from what the tool reports, and runs it again until it passes, so the file that lands is the one that already works.

Both check outputs, the install and the workflow run all stay with the run, and the pull request quotes them. A team with several Tokio services runs this across all of them at once and gets one pull request per repository, each with its own allow list derived from its own lockfile rather than copied from a sibling.

## Frequently asked questions

### Why run the check with --all-features?

Because the `otel` feature adds four optional dependencies and everything under them to the graph, and a `deny.toml` written against the default features would pass locally and fail the moment someone builds with `--features otel`, which the existing `CI` workflow does. It is also the GitHub action's default `arguments` value, so the file is checked the same way in CI.

### Why is multiple-versions set to warn?

Because `Cargo.lock` already carries two versions each of `syn`, `socket2`, `regex-automata` and `regex-syntax`, brought in by transitive dependencies the project does not pin. Setting it to `deny` would fail the first run on things nobody can change without upgrading other crates, which is a separate pull request. The duplicates are listed in the description so a later `cargo update` can retire the warning.

### Why keep advisories on continue-on-error?

Because an advisory is published on the RustSec side, not in the repository, and a strict job would turn every unrelated pull request red the morning one lands. The action's README recommends this split for the same reason. The job still runs and shows the failure; it just does not block until the team decides it should.

### Does this replace Dependabot or cargo audit?

No. cargo-deny checks the graph that is already in `Cargo.lock` for licenses, duplicates, sources and advisories; it proposes no upgrades. A project that wants update pull requests still adds Dependabot, and this check is what judges them when they arrive.

## More Tokio jobs

- [Add Clippy to CI for a Tokio Project](https://getrush.ai/run/add-clippy-to-ci/tokio/)
- [Add a Config File to a Tokio Server](https://getrush.ai/run/add-config-file/tokio/)
- [Add Code Coverage to CI for a Tokio Service](https://getrush.ai/run/add-coverage-to-ci/tokio/)

## The same job on other stacks

- [Add cargo-deny to a Rust Workspace](https://getrush.ai/run/add-cargo-deny/rust/)
- [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/)

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