
PYPILINE: Malicious PyPI Package Detection via Suspicious API Knowledge and Agent Workflow
PYPILINE is a malicious PyPI package detection system that builds a structured knowledge base of suspicious APIs from static analysis (AST + API call graphs) of known malicious packages, then uses an LLM agent workflow with RAG to retrieve that knowledge base and perform semantic analysis of new packages, outputting structured evaluation reports. The authors report 96.7% precision, 99.6% recall, and 98.1% F1 (5.7–21.6 points above baseline tools), with ~0.6s average detection time per package under 30 concurrent threads, plus an empirical study of common attack strategies and frequently abused APIs in PyPI malware.
What it is
PYPILINE is a research prototype for detecting malicious PyPI packages by combining a statically-built "suspicious API" knowledge base with an LLM agent workflow. The summary covers the architecture and headline metrics; what it omits is how the knowledge base is ranked, its size, the dataset composition, and the concrete attack patterns the empirical study names — the parts a defender would actually turn into detections.
How it works
The offline phase parses each known-malicious package into an AST, walks all function-call nodes to build a package-level API call graph G = (V, E) (nodes = std lib, third-party, and user-defined APIs; directed edges = caller→callee), then scores each API node by degree centrality (in-degree + out-degree, averaged across all malicious-package graphs). High centrality is treated as evidence an API is a "hub" of malicious behavior (e.g. os.system). The ranked candidates are then manually reviewed against prior research, yielding a fixed knowledge base of 300 malicious APIs stored as (API name, malicious-behavior description) pairs.
Online, all .py files of a package under test are concatenated into one document (filenames kept as section headers) and fed, with the retrieved knowledge, into the agent. The agent invokes external tools — a vector DB for RAG retrieval and a mail server to auto-send the final report.
Attack patterns the study names
The empirical portion classifies malicious behavior by execution stage, useful as a detection taxonomy:
- Install-time — tampering
setup.pyor inserting commands incmdclass; the paper's Case #2 shows aPostInstallCommandclass subclassing setuptools' install command and overridingrun()to run silently after install. - Import-time — malicious init code in the package entry file executed on
import. - Runtime — payload hidden in functions, triggered conditionally for stealth.
Named techniques: install-time execution, code obfuscation, and downloading remote executables. Case #1 (tpmchttp) spawns a hidden PowerShell via subprocess, runs a Base64 command that Invoke-WebRequest-downloads Esquele.exe, renames it WindowsCache.exe to the home dir, and runs it via Invoke-Expression (-WindowStyle Hidden, CREATE_NO_WINDOW). Case #2 fingerprints Linux hosts via /proc/uptime, platform.release(), and socket.gethostbyname(socket.gethostname()), then exfiltrates over a raw TCP socket.
Caveats
Numbers in the abstract vs. body don't fully align — the abstract cites a 9,408 malicious / 14,005 benign eval set (23,413 analyzed), while a contributions bullet mentions "5000 PyPI packages." The knowledge base depends on a manual review step, so it isn't fully automated, and the paper is a preprint with no released tool or code referenced in the fetched text.
Techniques named here
- Static analysis of AST and API call graphs
- Dynamic analysis
- RAG
- Machine learning / LLM-based detection
Related in Supply Chain


