Automatic fixing with snyk fix
Release status and feature availability
The snyk fix command is in Closed Beta and available only for Enterprise plans. Snyk welcomes feedback at snyk-fix-feedback@snyk.io.
For more information, see Plans and pricing.
The snyk fix
CLI command automatically applies the recommended updates for supported ecosystems. Ensure you use the latest version of CLI (v1.715.0 or later) to use snyk fix
. The command is supported only for Python.
When you use the snyk test
command, actionable fixes for supported ecosystems appear in the scan results as shown in the example that follows.
The following example shows the output of running snyk fix
.
Note that only successful test results are forwarded to snyk fix
. In addition, all unsupported ecosystem test results are skipped.
Enabling snyk fix
To enable snyk fix during the beta period, click on Settings > Snyk Preview. Enable the snyk fix feature and click Save changes.
The snyk fix
command supports all the snyk test
command options and has the following additional options:
--quiet
- Suppress all output to the command line.--dry-run
- Run almost all the logic and display output, but do not make the final changes to the relevant files. Show a preview of the changes.--sequential
- Install each dependency update separately one at a time (the default is to install all at once). The default is much slower, but helps increase the number of successful updates by allowing some updates to fail and the process to continue.
Python support
Pip Projects with
requirements.txt
files or custom named files, for exampleprod.txt
.Pipenv Projects with
Pipfile
andPipfile.lock
filesPoetry Projects with
pyproject.toml
andPoetry.lock
files
Usage examples
snyk fix --file=requirements.txt
snyk fix --file=base.txt --package-manager=pip
snyk fix --all-projects
Requirements with -r
directives
-r
directivesWhere the requirements.txt
looks like this, both base.txt
and requirements.txt
are updated if needed:
Direct dependency upgrades (dependencies stated in the manifest)
Direct dependency upgrades are applied in the relevant files. All files referenced are found and updated.
Pins (transitive dependencies that are pulled in via direct dependencies)
Pins are applied in the manifest file that was tested.
If multiple files are tested but are related (for example one requires the other), Snyk starts to apply changes to the files higher up in the directory structure.
Snyk detects previously fixed files and skips applying fixes to them again.
Projects that use constraints.txt
constraints.txt
Constraints files are requirements files that control only which version of a dependency is installed, not whether it is installed or not. Their syntax and contents are nearly identical to requirements files. There is one key difference: including a package in a constraints file does not trigger installation of the package. For more information, see User Guide - pip documentation v21.0.1.
Direct dependency upgrades (dependencies stated in the manifest)
Direct dependency upgrades are applied in the relevant files. All files referenced are found and updated.
Pins (transitive dependencies that are pulled in via direct dependencies)
All transitive dependencies are pinned in the constraints.txt
file if referenced with the -c
directive in the requirements manifest file.
Python (pipenv
)
pipenv
)Snyk delegates to pipenv
directly to update dependencies to the specified recommended versions. All pipenv
environment variables and behaviors are preserved as much as possible.
Python (poetry
)
poetry
)Snyk delegates to poetry
directly to update dependencies to the specified recommended versions. All poetry
environment variables and behaviors are preserved as much as possible.
Troubleshooting
Run in debug mode to get more information on any errors.
This provides a very verbose output that can help diagnose issues or can be sent to Snyk for debugging.
Last updated