Konstantin Schütze at Astral maps where automated Python builds can run code that nobody on the team reviewed. A lockfile can fix which package files a project accepts. GitHub Actions, tools fetched during a build, and the job that publishes the release need their own controls.

Pin what actually runs

Pin the Python artifacts, not just their versions. A release can have several files for different platforms. A cryptographic hash is a fingerprint of one file’s contents. Record trusted hashes for the files your installations may use, including indirect dependencies. Review changes to the lockfile before approving new versions.

Apply the same rule to GitHub Actions and downloads. An action’s version tag can move. Use a reviewed full commit ID or opt into GitHub’s workflow dependency lockfiles, still in public preview. Check separately for binaries the action downloads while it runs. Verify those against hashes recorded through a trusted review process before executing them.

Include the tools that build and test the project. A formatter or test runner fetched on demand can run with the job’s permissions. Lock those tools and their dependencies too. If your targets have suitable prebuilt packages, forbid automatic builds from source. When a source build is necessary, review and constrain its build dependencies separately.

Give publishing its own job

PyPI Trusted Publishing lets PyPI verify the release workflow’s identity and grant it a project-scoped token valid for 15 minutes. That replaces a long-lived upload token in CI. Give the release job only the access it needs. For a team release, protect the publishing environment with an independent approval and keep ordinary test jobs outside it.

A delay before accepting brand-new dependency releases can give maintainers time to notice a bad upload. Set a process for taking an urgent security fix without waiting out that delay.

Caveat: Astral makes uv, one tool the article recommends. This is defensive guidance, not a new incident report: a valid hash proves you got the file you selected, not that the file was safe when you selected it.