Lion Cipher Lab

Catch hallucinated package names in LLM-generated code before you pip install them (slopsquatting defence, stub assistant)

Why it matters

Coding assistants now write a lot of the glue code in security teams - the script that looks up a hash, parses a pcap, scans a folder with YARA - and every one of those answers ends with an install line. Sometimes the package on that line does not exist. The model invented it, because the name sounds like what a package for that job would be called. Spracklen and colleagues measured this across 16 code-generating models and 576,000 samples: at least 5.2% of packages from commercial models and 21.7% from open-source ones were hallucinated, over 205,000 unique invented names - and, crucially,…

What you'll learn

Steps in this lab

  1. The words first: hallucinated packages, slopsquatting, and the fact that the assistant here is a stub
  2. Open a terminal and make a scratch folder (Windows, macOS, Linux)
  3. Build the world: 200 answers from a stub assistant, and a synthetic registry snapshot
  4. The assistant is a STUB and the registry is SYNTHETIC - here is exactly what that does and does not mean
  5. Write the gate: read imports with ast, drop the standard library, map import names to distributions, fail closed
  6. Gate v1, existence only: measure the hallucination rate and how much of it repeats
  7. The honest negative: squat the repeated names, and watch the existence check wave them through
  8. Gate v2: allowlist first, then age and release history, then a human - and measure both modes
  9. OPTIONAL, online: read one real project's metadata from the PyPI JSON API (no install)
  10. Pin what you approved: hash-checking mode, so the approved name cannot be swapped underneath you
  11. Why this, not that - and when the gate is theatre
  12. Ship it: the policy, what to log, and clean up

Open the full interactive lab →