Safeguard
Developer Tools•

How do I vendor Rust dependencies with cargo vendor?

Run cargo vendor, add the printed source replacement to .cargo/config.toml, and build offline. Steps, useful flags and what vendoring does not fix.

Safeguard Security Team
3 min read

Run cargo vendor in your project. It downloads every crates.io and git dependency into a local vendor directory and prints a config snippet. Save that snippet to .cargo/config.toml, and Cargo will build from the local copies without touching the network.

Steps

  1. Make sure Cargo.lock is committed and current, so you vendor exactly what you build.
  2. Run the vendor command, redirecting the printed config into place:
cargo vendor > .cargo/config.toml
  1. Check that the file contains a source replacement like this:
[source.crates-io]
replace-with = "vendored-sources"

[source.vendored-sources]
directory = "vendor"
  1. Build with the locked and offline flags to prove nothing reaches the network:
cargo build --locked --offline
  1. Commit vendor and the config if your policy is to keep sources in the repository.

Flags worth knowing

FlagEffect
versioned-dirsPuts the version in every vendored directory name, which makes history easier to read
lockedFails if the lockfile is missing or would change
no-deleteKeeps existing contents of the vendor directory
syncVendors extra manifests into the same directory
respect-source-configHonors existing source settings when downloading

By default Cargo ignores any existing source configuration while vendoring.

What vendoring gives you

You get a build that does not depend on the registry being reachable, and a place where every line of third party code is visible in a diff. When a dependency changes, the change shows up in a pull request that a human can read.

What it does not give you

Vendored code is still third party code. Vendoring does not scan it, does not tell you when an advisory is published, and does not stop a bad version from being copied in. You still need advisory checks against the lockfile, and review on vendor diffs. Cargo also treats vendored sources as read only. To change one, use a patch section or a path dependency rather than editing the directory.

Keeping it fresh

Treat updates as a routine job. Update the lock, re-run the vendor command, review the diff, run your checks, and merge. If nobody owns that routine, a vendored tree turns into a frozen snapshot of old, vulnerable code.

Try it yourself

Click through it at your own pace, or open it full screen. Look at how new advisories are matched to components you already ship.

Quick check

Does cargo vendor include git dependencies?

Yes. It downloads all crates.io and git dependencies for the project.

Can I edit a vendored crate to patch a bug?

Not in place. Cargo treats vendored sources as read only. Use a patch section or a path dependency pointing at a local copy.

Safeguard continuous monitoring and SBOM and dependency scanning can watch the components you ship for new advisories, and a free scan is available at gold.safeguard.sh/scan.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.