AI Coding Agents & Dependencies: What to Check
In this article
Before letting an AI coding agent install or update dependencies, you must check the agent's permission scope, the dependency's provenance and license, and whether the changes are reproducible. This article explains the specific risks and the practical checks you should run before, during, and after the agent modifies your project's dependency tree.
Why AI Agents Change Dependencies Differently
Traditional tools like npm install or pip install are deterministic: you run a command, and the package manager resolves versions based on your lockfile. An AI coding agent, however, may autonomously decide to add a new package, update a transitive dependency, or change a version range to fix a bug or satisfy a request. This introduces a new class of risk because the agent's decision-making is probabilistic and may not follow the same conservative logic a human developer would.
For example, an agent asked to "fix the build" might update a major version of a library to get a newer API, inadvertently breaking backward compatibility. Or it might add a package with a similar name to the one you intended (typosquatting is a real threat). The key difference is that the agent is not just executing a command; it is making a judgment call about which dependency to change and how.
What to Check Before the Agent Runs
Before you even let the agent touch your project, set up guardrails. Here's a practical checklist:
- Scope of permissions: Does the agent have write access to your package manifest and lockfile? Can it execute arbitrary shell commands? Ideally, restrict it to editing source files only, and require human approval for any dependency-related changes.
- Lockfile presence: Ensure your project has a lockfile (e.g.,
package-lock.json,poetry.lock,requirements.txtwith pinned hashes). Without it, the agent may install floating versions, making builds non-reproducible. - Network access: Can the agent reach public registries? If your project uses a private registry or an internal mirror, make sure the agent's environment is configured to use it, otherwise it might pull packages from the public internet, which could be a security risk.
- Backup and rollback plan: Commit your current state or create a branch before letting the agent work. This gives you a clean rollback point if the agent introduces a bad dependency.
Checking Dependency Provenance and Authenticity
Not all packages are created equal. When an AI agent proposes a new dependency, you should verify:
- Package name and registry: Is the package from the official registry (npm, PyPI, Maven Central)? Check for typos or subtle variations (e.g.,
lodashvs.lodahs). - Maintainer reputation: Who publishes the package? Is it a well-known organization or a single individual with a history of releases? Look at the maintainer's profile and the package's release history.
- Download counts and community usage: A package with millions of weekly downloads is more likely to be legitimate than one with only a few hundred. But beware: some malicious packages have been promoted via fake stars and downloads.
- License compatibility: Does the package's license (MIT, Apache, GPL) conflict with your project's license? An agent might not check this, so you must.
- Content review: If the package is small, read its source code. Look for suspicious patterns like obfuscated code, calls to external URLs, or attempts to read environment variables (e.g.,
process.envin Node.js) that aren't necessary for the package's purpose.
Semver, Version Ranges, and Lockfiles
AI agents often work with version ranges like ^1.2.3 or ~1.2.3. These allow automatic updates within a range, which can be convenient but also introduces risk. A new patch or minor version could contain a vulnerability or a breaking change (even if it shouldn't, per semver).
Always check what the agent actually wrote in the manifest. Did it change a range? Did it pin an exact version? Did it update the lockfile to match? A common mistake is that the agent updates the manifest but forgets to run the package manager to update the lockfile, leading to inconsistencies between what's declared and what's installed.
Best practice: after the agent finishes, run npm install (or your package manager's equivalent) to ensure the lockfile is in sync. Then review the diff to see exactly which packages were added, removed, or updated, and their version numbers.
Security and Vulnerability Scans
Before committing any dependency change, run a vulnerability scan. Tools like npm audit, pip-audit, or safety check your dependency tree against known vulnerability databases. An AI agent might not do this, or might ignore warnings to complete its task.
Additionally, consider using a Software Composition Analysis (SCA) tool that integrates with your CI/CD pipeline. These tools can block merges if a new dependency introduces a known vulnerability. If the agent added a package that fails the scan, you should reject that change and ask the agent for an alternative.
Also check for license compliance: some packages have restrictive licenses (e.g., GPL) that could affect your ability to distribute your software. Tools like license-checker or pip-licenses can list all licenses in your dependency tree.
Testing After Installation
Installing a new dependency is not the end; you must verify it works in your environment. Run your test suite, but also do a manual smoke test of the features that the dependency touches. An AI agent may have written code that uses the new library, but it might not have tested all edge cases.
Check the following:
- Does your application build without errors?
- Do all existing tests pass?
- Are there any runtime errors or warnings in the console?
- Does the new dependency work with your project's Node version, Python version, or framework?
If you have a staging environment, deploy there first. If the agent changed a dependency that affects performance (e.g., a new image processing library), benchmark before and after to ensure no regression.
Common Pitfalls and Misconceptions
One common misconception is that AI agents are "smart" enough to choose the best dependency. In reality, they are pattern-matching based on training data, and may select a library that is popular but not the best fit for your specific use case. They also might not consider the maintenance status or the project's future needs.
Another pitfall is allowing the agent to update dependencies automatically as part of a larger refactor. This can lead to a huge diff that mixes functional changes with dependency changes, making review difficult and increasing the chance of introducing bugs.
Finally, do not assume that because the agent's changes pass CI, they are safe. CI might only run unit tests, not integration tests or security scans. Always do your own review.
Frequently Asked Questions
Can AI agents install dependencies without me knowing?
Yes, if you grant them full autonomy and they have network access. That's why you should always run the agent in a sandboxed environment and review the diff before merging. Most agent platforms allow you to require human approval for specific actions, such as running package manager commands.
Should I let the agent update my lockfile?
Yes, but only after you review the changes. The lockfile is critical for reproducibility, so the agent should update it whenever it changes the manifest. However, you should verify that the lockfile changes are consistent with the manifest changes and that no unexpected packages were added.
What if the agent adds a package with a known vulnerability?
Reject the change and ask the agent to find an alternative. You can also configure your vulnerability scanner to fail the build if a new vulnerability is introduced. The agent should be able to suggest a different package or an older version that is not vulnerable.
How do I know if a dependency is safe to use?
There's no absolute guarantee, but you can reduce risk by checking the package's popularity, maintenance activity, license, and source code. Also, run a vulnerability scan and check if the package is used by other reputable projects. For critical dependencies, consider vendoring the code and reviewing it thoroughly.
Can AI agents handle monorepos with multiple packages?
Yes, but it's more complex. The agent needs to understand the workspace structure and update the correct manifests and lockfiles. You should test this in a staging environment and verify that all packages in the monorepo still build and test correctly after the changes.
What's the best way to review an agent's dependency changes?
Use a diff tool to see exactly what changed in your manifest and lockfile. Look for unexpected additions, removals, or version changes. Then run your tests and a vulnerability scan. If possible, run the application locally and manually test the affected features.