# Add mix audit Dependency Scanning to an Elixir Project

Yes. An agent adds mix_audit to your Elixir project, runs it against mix.lock in its sandbox, wires it into CI next to your existing checks and opens a pull request.

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

## What the agent does

The agent reads what the project already checks before adding a scanner. In an application like hexpm/hexpm, `mix.exs` targets `elixir ~> 1.20` and lists 116 `deps` entries, including `phoenix ~> 1.6`, `ecto_sql ~> 3.0`, `oban ~> 2.23`, `sentry ~> 14.0`, `plug_attack`, `broadway_sqs` and a long run of `lumis_wasm_*` grammar packages at `~> 0.26.0`, plus three dependencies pinned to git commits: `finch` with a comment explaining a connection-pool bug, `git_diff`, and `hex_core` from GitHub until a release ships. There is no `mix_audit`, `sobelow` or `credo` in `deps`. `.github/workflows/main.yml` runs on `ubuntu-24.04` with OTP 29.1 and Elixir 1.20.4, a `format` job that runs `mix compile --warnings-as-errors`, `mix format --check-formatted` and `mix ecto.setup` against a `postgres:18` service, a `test-hexpm` job running `mix test`, and a `test-hex` matrix that clones the Hex client at three branches. Every action is pinned to a commit SHA with a version comment. `dependency-review.yml` runs `actions/dependency-review-action` on changes to `mix.exs`, `mix.lock` and workflows, and `dependency-submission.yml` sends the dependency graph with `erlef/mix-dependency-submission`.

That matters because GitHub's dependency review covers advisories GitHub knows about, while `mix_audit` checks `mix.lock` against the Hex advisory database that Elixir maintainers publish to, so the two overlap but do not coincide. The agent adds `{:mix_audit, "~> 2.1", only: [:dev, :test], runtime: false}` to `deps`, runs `mix deps.get` and then `mix deps.audit` in the sandbox against the real `mix.lock`. It reads the result rather than assuming it is clean: for each finding it records the package, the advisory id, the affected and patched versions, and whether the project's requirement already admits the fix.

Then it adds the check to CI. It creates an `audit` job in `main.yml` that reuses the `erlef/setup-beam` step at the same pinned SHA and the same `otp` and `elixir` env values, restores the `deps` cache with the existing key pattern, runs `mix deps.get` and `mix deps.audit --format human`. It runs with `MIX_ENV: test` so the `only: [:dev, :test]` dependency is present, needs no Postgres service, and keeps `permissions: contents: read`. It also adds the job to the same `if:` condition the other jobs use, so a pull request from a branch in the repository does not run it twice. The three git-pinned dependencies have no Hex version, so `mix deps.audit` skips them; the agent says so in the pull request so nobody mistakes silence for a clean result.

If `mix deps.audit` reports a vulnerable package, the agent does not bump it in the same pull request. It adds `--ignore-advisory-ids` with the exact ids to the CI step, each with a comment and a date, so the job turns green on a known state, and lists the advisories with their fixed versions in the description for a separate upgrade. If the audit is clean, the step runs without ignores. It finishes with `mix format --check-formatted` on `mix.exs` and quotes every command's output.

## Start it with one API call

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

```json
{
  "agent": "claude",
  "input": "Add mix_audit dependency vulnerability scanning to this Elixir project and open a pull request. Read mix.exs, mix.lock and every workflow under .github/workflows first. Add mix_audit to deps for dev and test only with runtime false, run mix deps.get and mix deps.audit in the sandbox against the real mix.lock, and read the result. Add an audit job to the main CI workflow that reuses the existing pinned setup-beam action and OTP and Elixir versions, restores the deps cache the same way the other jobs do, and runs mix deps.audit with MIX_ENV=test and no database service. If the audit finds a vulnerable package, do not upgrade it here: ignore those advisory ids in the CI step with a dated comment and list them with their fixed versions in the description. Note which git-pinned dependencies the audit cannot check. Run mix format --check-formatted and quote every command's 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 changes `mix.exs`, `mix.lock` and `.github/workflows/main.yml`. `mix.exs` gains one `deps` entry, `mix.lock` gains `mix_audit` and its own dependencies, and the workflow gains an `audit` job built from the same pinned actions and versions as its neighbours. No application code changes.

The description quotes `mix deps.audit --format human` from the sandbox: either a clean result with the number of packages checked, or a table of advisories with the affected package, the id and the patched version, together with the matching `--ignore-advisory-ids` entries the CI step carries until an upgrade lands. It names the git-pinned dependencies the audit skips. The repository's own `main.yml` runs on the pull request, so the new job runs once on GitHub as well.

Before merging, a reviewer checks that the job's `if:` and cache key match the other jobs, that any ignored advisory is tracked as an upgrade task, and that `mix_audit`'s version requirement sits in the same style as the rest of `deps`. If they want the job to fail a pull request only for high-severity advisories, that is a flag on the same step.

## Run it on every Monday morning

Once the job is in CI it runs on every push and pull request. For a scheduled sweep that also catches advisories published between commits, add an automation in the console with a `schedule` trigger, `cron` set to Monday morning in your `timezone`, and a prompt that runs `mix deps.audit` in the Project's repository and opens a pull request only when a new advisory appears, naming the package and the fixed version. Each scheduled run is a fresh sandbox reading the current `mix.lock`, so a clean week produces nothing.

From your own server, the same run is one `POST /o/{org}/sessions` per repository with the repository in `resources`; `GET /o/{org}/github` lists the repositories your installation reaches, so a weekly script can start one run per Elixir project. Give the API key a webhook URL and Rush POSTs `run.completed` or `run.failed` when each turn ends, with `session_url` to read the result, and send a fresh UUID as `request_id` so a retried call returns the run already started.

## Why run it on Rush?

The useful part of adding a scanner is the first run against the real lockfile, and that run needs the project's Erlang and Elixir versions, its dependency tree fetched, and a careful reading of what the advisories say. In its own sandbox the agent installs the exact OTP and Elixir the workflow pins, fetches deps, runs the audit and keeps the output in the run's record, so the pull request tells you the state of your dependencies today and what CI will enforce from now on.

Nothing is installed on a laptop and no `_build` is left behind. The same request runs across every Elixir repository a team owns at once, each in its own sandbox, each with its own pull request and its own audit result.

## Frequently asked questions

### We already run GitHub's dependency review. Why add mix_audit?

They read different sources. `dependency-review-action` uses the GitHub Advisory Database, while `mix_audit` reads the Hex advisory data the Elixir security working group maintains, and advisories appear in one before the other. Running both costs one short job and the agent's pull request shows what the Hex side reports today.

### Will the new job fail CI as soon as it merges?

Only if the audit is clean or every current finding is ignored by id. The agent runs the audit first and, when it finds something, adds dated `--ignore-advisory-ids` entries so the job starts green on a known state, with the upgrades listed in the description for a separate pull request.

### What about dependencies pinned to a git commit?

`mix deps.audit` matches packages by Hex name and version, so a git dependency has nothing to match and is skipped. The agent lists those packages in the pull request so the reviewer knows they are unaudited; in hexpm that is `finch`, `git_diff` and `hex_core` until their releases ship.

### Does the audit job need the Postgres service?

No. `mix deps.audit` only reads `mix.lock` and the advisory database, so the job skips the `services` block the format and test jobs use and finishes faster. It keeps the same cache key pattern so the `deps` restore works on the first run.

## More Elixir jobs

- [Add Property-Based Tests to an Elixir Library](https://getrush.ai/run/add-property-tests/elixir/)
- [Add a Release Workflow to an Elixir Library](https://getrush.ai/run/add-release-workflow/elixir/)
- [Add Sobelow Security Scanning to a Phoenix App](https://getrush.ai/run/add-sobelow/elixir/)

## More jobs like this: Upgrade dependencies weekly

- [Add NuGet Vulnerability Auditing to a .NET Solution's CI](https://getrush.ai/run/add-nuget-audit-to-ci/dotnet/)
- [Add pip-audit to a Python Project's CI](https://getrush.ai/run/add-pip-audit-to-ci/python/)
- [Set Up Renovate for an Ansible Role](https://getrush.ai/run/add-renovate/ansible/)

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