Join our Newsletter — 33% off our NHI Course
Home› FAQ› Cyber Security› Why does pip package download behavior increase the…
Cyber Security

Why does pip package download behavior increase the risk of supply chain attacks in Python environments?

← Back to all FAQ
By NHI Mgmt Group Editorial Team Updated October 31, 2026 Domain: Cyber Security

The risk comes from the fact that pip may process package metadata by running setup.py, even when a developer only intends to download files. Because setup.py is executable code, an attacker can hide malicious actions there and trigger them before installation. That makes simple package retrieval a potential execution path, especially when teams assume download-only activity is harmless.

Why download-time package behavior is risky in Python

Package download is not always a passive file transfer. In Python, pip can inspect package metadata in ways that execute repository-provided code paths, so the boundary between “just downloading” and “running untrusted logic” can be much thinner than teams expect. That matters because supply chain abuse often starts before installation, when reviewers assume nothing executable is involved.

This is why AI Supply Chain Security and AI-BOM Guide is still relevant here: the same control problem appears across package ecosystems, where provenance, package contents, and secret containment all need to be treated as part of the trust decision, not as a post-install concern.

How an attacker turns download-only trust into execution

The practical risk is that metadata handling, source distribution inspection, and build preparation can trigger attacker-controlled code paths before a package ever lands in a runtime environment. In other words, the security assumption “I only downloaded it” can fail if the download workflow itself causes evaluation of setup logic or package-provided build steps. That gives an attacker an earlier opportunity to steal credentials, fingerprint the environment, or stage a payload.

Python packaging is especially exposed when developers rely on source distributions from public registries, because those artifacts may contain code that is evaluated during metadata generation or build preparation. A strong illustration is eslint-scope npm compromise 2018, where a compromised package used install-time logic to steal registry tokens from developer environments.

Even when the end goal is not immediate malware execution, this early trust boundary is enough for supply chain attackers to harvest secrets, alter dependency resolution, or plant malicious follow-on behavior. That is why package retrieval and package execution must be treated as adjacent phases with different trust levels, not as a single harmless download step.

What defenders should verify before they trust a Python package

Teams should verify whether their tooling is fetching a source distribution, building from source, or using a prebuilt artifact, because those paths do not carry the same risk. They should also check whether the package source is pinned, whether provenance is verified, and whether the resolver is allowed to prefer unexpected transitive dependencies. The safer default is to treat any package that can execute code during metadata or build processing as hostile until proven otherwise.

For broader package supply chain control, SLSA is useful because it frames build provenance and artifact integrity as core defenses, which is exactly what is missing when a package can influence behavior before installation. Likewise, NIST SSDF (SP 800-218) reinforces secure acquisition and build practices that reduce the chance of trusting arbitrary package behavior.

Where public registries or maintainer workflows are part of the attack path, external guidance on supply chain threats is also relevant. OpenSSF provides practical ecosystem guidance for reducing package and dependency risk, while ENISA Threat Landscape is useful for understanding how software supply chain abuse fits into the broader threat picture.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

SLSA, NIST SP 800-53 Rev 5, OWASP ASVS and CIS Controls v8 set the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
SLSABuild Provenance and IntegrityPackage download behavior is a supply-chain trust problem involving artifact provenance.
Recommendation — Require provenance checks for packages and artifacts before they reach build or deployment steps.
NIST SP 800-53 Rev 5SI-7 — Software, Firmware, and Information IntegrityUntrusted package behavior can compromise software integrity during acquisition and build.
CM-5 — Access Restrictions for ChangeAttackers can abuse package workflows to introduce unauthorized changes via dependency paths.
Recommendation — Validate package integrity and restrict untrusted code execution during dependency handling. Restrict who can alter dependency sources and approved package inputs.
OWASP ASVSV15 — Secure Coding and ArchitectureSecure software architecture should account for untrusted code paths in dependency handling.
Recommendation — Design build and dependency workflows so untrusted package logic cannot execute by default.
CIS Controls v8CIS-16 — Application Software SecurityPackage handling is part of software security and dependency risk management.
Recommendation — Review and harden software acquisition and dependency practices to reduce supply chain risk.

Practitioner Guidance

What to prioritise: treat package acquisition as a security-sensitive step, not a harmless prelude to installation. If a package can execute code during metadata processing or build preparation, it deserves the same scrutiny you would give to any other execution path that reaches a developer workstation or CI runner.

What to verify: confirm whether your pipeline allows source builds from untrusted packages, whether it isolates build environments, and whether registry credentials are present during dependency resolution. If secrets are reachable during download or build evaluation, the blast radius is already too large.

Common mistake: teams often focus on malicious imports and never inspect the package retrieval phase. That misses the point where attackers can first observe the environment, access tokens, or alter downstream behavior before any application code is installed.

Practitioner takeaway: the security decision is not “did we install the package,” but “did we allow untrusted package logic to execute while we were still deciding whether to trust it.”

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Reviewed and updated by the NHIMG editorial team on October 31, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org