Skip to content
ML Academy

LLMs, GenAI, RAG, agents, evaluation · insight-1611

Install only allow-listed packages when a model suggests code dependencies

Evidence type
practitioner heuristic
Difficulty
medium
Roles
ML engineer, Applied AI
Industries
saas

Summary: situation, action, reason, boundary

  1. Situation

    A coding assistant or code-writing agent proposes imports, and a developer or pipeline runs the install.

  2. Action

    Resolve suggested dependencies against an internal mirror or allow-list with pinned hashes. Send names that are new, rarely downloaded or absent from the lockfile to human review, and run first installs in an isolated build without credentials.

  3. Reason

    Spracklen and colleagues measured hallucinated package names in 576,000 code samples from 16 models, at least 5.2% on average for commercial and 21.7% for open-source models, so non-existent names recur at scale.

  4. Boundary

    Code generation that can reach a package manager, including notebook and CI agents.

Symptom or risk

The suggested package does not exist; an attacker who registered that name on a public index now runs code on your build machine.

Exceptions

Disposable sandboxes with no network access to internal systems and no secrets.

Trade-offs

New libraries need an approval step, which slows experiments.

Pitfalls

Checking only that the name exists on the public index, which is exactly what the attacker arranges.

Lessons and concepts

Claims and their sources