Package Installation Policy
In this article
- Explain why installing a Python package already runs code inside the sandbox.
- Write a pinned, hashed requirements file and the pip command that installs it from a mirror with no source builds.
- Decide which install a policy blocks and which control blocks it, for a near-miss package name, an unlisted dependency and a source-only package.
- Keep the install manifest with the run so the install can be repeated and checked later.
- Terms defined here: install script, typosquatting, dependency pinning.
Overview
The code an AI assistant writes often starts with import pandas, and someone has to install that library before the code can run. That step feels like setup, so it is easy to wave through. Yet a package can carry code of its own, a dependency can arrive that nobody chose, and a name one letter off can fetch something else entirely.
You will see why an install is code running inside your sandbox, and set up three controls that each stop one kind of bad package. Given a requirements file and the packages your mirror (an internal copy of a package index) holds, you can then say which install fails, which control fails it, and which install goes through.
Sign in to keep reading
The rest of this article opens with an account. An account also keeps your progress and quiz results on every device, and lets you follow news for up to five topics.
Still to read in this article
- Installing runs code
- Three ways a bad package gets in
- Pins and hashes
- Which control stops which attack
- The legitimate install and its manifest
- The rule at work
- Common mistakes
- In production
- Sources
- Check yourself, 13 questions