Safeguard
Developer Tools•

Do you need conda-lock if you already have an environment.yml?

Environment.yml states what you want. A conda-lock file records exactly what was solved, for each platform. See when the extra file earns its place.

Safeguard Security Team
3 min read

If you need the same environment on more than one machine or date, yes, you want a lock file. An environment.yml states desired packages, and the solver may choose differently later. The conda-lock tool records the exact solution for each platform you target, including a pip section.

Definition

The conda-lock project describes itself as a lightweight library that generates fully reproducible lock files for conda environments. It does this by performing a conda solve for each platform you want. Installing from the generated file means the conda solver is not invoked, because the answer is already written down.

The project explains why: environment.yml files are useful for defining desired environments, but sometimes you need to exactly reproduce one by downloading the packages needed, for example in a gitops style setup that provisions environments in several places.

Basic usage

The project readme shows this flow:

conda-lock -f environment.yml -p osx-64 -p linux-64
conda-lock install -n my-locked-env

It writes conda-lock.yml by default. If a lock file already exists, it is used as a constraint when regenerating, so you can add a package while keeping the rest locked. There is also an option to render single platform files for use with conda create.

What it adds

  • One lock file for several platforms, instead of separate files by hand.
  • A way to update one package at a time, such as an update flag followed by a package name, while the rest stay put.
  • Locking for the pip section of environment.yml, using a vendored copy of a dependency solver.
  • Categories, so production and development dependencies can sit in separate files.

What it does not do

A lock file fixes versions. It does not check them for vulnerabilities, and a locked vulnerable version stays vulnerable. It also adds a tool to your chain, so install it in an isolated environment as the readme recommends, to avoid dependency conflicts.

SituationEnvironment.yml aloneAdd a lock file
Solo explorationFineOptional
Shared analysis that must rerunRiskyRecommended
Production job or image buildRiskyRecommended
Audit or evidence requestWeakStrong

A routine that works

  1. Edit environment.yml, since that is the intent.
  2. Regenerate the lock file in CI and commit it.
  3. Build images and environments only from the lock file.
  4. Scan the lock file contents on a schedule, because new advisories appear after you lock.
  5. Update packages deliberately, one by one, and re-lock.

For a broader look at pinning data projects see /resources/blog/pin-python-dependencies-in-data-projects.

Try it yourself

Click through it at your own pace, or open it full screen. Look for how a pinned package can still raise a new alert later.

Safeguard offers SBOM and dependency scanning, plus continuous monitoring, so a locked list can keep being checked. Run the free scan at gold.safeguard.sh/scan.

Quick check

Does conda-lock replace environment.yml?

No. It reads environment.yml as input and writes the solved result.

Is a locked environment automatically secure?

No. Locking fixes versions, and a fixed vulnerable version stays vulnerable.

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.