Sub topic 3
Lockfiles, Hash Pinning, and Restricted Install Scripts
Assume you know basic pip or npm commands, public registries, and AI coding assistants. These controls reduce the chance that a hallucinated package name becomes installed code.
Lockfiles, Hash Pinning, and Restricted Install Scripts
A lockfile records the exact dependency versions selected for a project. Commit requirements.txt generated by pip-tools, package-lock.json for npm, or the equivalent file for your package manager. In CI, install from the lockfile rather than resolving names again.
Hash pinning records the expected cryptographic hash of each package file. The installer rejects a file whose hash differs from the recorded value. This limits unexpected replacements and prevents unreviewed packages from entering the build.
# Python: generate hashes, then reject unlisted or mismatched files
pip-compile --generate-hashes requirements.in
pip install --require-hashes -r requirements.txt
# npm: use the committed lockfile and do not run lifecycle scripts
npm ci --ignore-scripts--ignore-scripts prevents npm lifecycle scripts from running during installation. It does not make the package safe: application code or a later build step can still execute it. Enable scripts only when a dependency requires them and the source has been reviewed.
What Model and Tool Builders Can Do
Coding tools should distinguish “the model suggested this name” from “this package exists.” A package-install tool can query the intended registry, reject missing names, show metadata, and require explicit approval. Sandboxed execution and network restrictions reduce damage if installation still occurs. Models should prefer documented packages and state uncertainty instead of inventing names.
Registry Defenses and Organizational Policy
Registries can detect rapid registration of names commonly produced by models, scan uploads, display provenance, and warn about suspicious maintainers or releases. Organizations should use an internal proxy or allowlist, require dependency review, block direct installs in CI, and record package versions and hashes in build logs.
If You Already Installed a Suspicious Package
Stop using the environment and isolate the machine or runner from sensitive networks. Preserve the package, installer output, lockfile changes, and relevant logs. Rotate credentials that were available to the process. Inspect source, entry points, lifecycle scripts, and filesystem or network activity. Rebuild from a known-good environment instead of trusting cleanup alone, then report the package to your registry and security team.
Exercise
Does a committed lockfile alone prove that a newly suggested package is safe?
Show answer
No. It proves which artifact will be installed, but you must still verify the package, owner, source, and behavior.