all postsblog / ai agent sandboxes

blog

Slopsquatting: When Your AI Agent Installs a Package That Doesn't Exist (Yet)

written by
Ajay Kumar
published
reading time
10 min read
topics

Ask a coding agent to parse some awkward dates and it will, now and then, reach for a library with a perfect name. Something like notreal-dateparse-utils or notreal-jsonschema-utils: a name that sounds exactly like a package that ought to exist, written with total confidence, followed by pip install. Sometimes the package does exist. Sometimes it does not, and the install fails, and the agent shrugs and tries something else. And sometimes it did not exist last month, but somebody noticed that models keep asking for it, and registered it.

That last case has a name now: slopsquatting. The term is usually credited to Seth Larson of the Python Software Foundation, and it describes a simple trade. Typosquatting bets that a human will mistype requests. Slopsquatting bets that a model will confidently invent a plausible name, and that it will invent the same one again for the next user who asks a similar question. The attacker does not need to guess what you will type. The model already told them.

I build PandaStack, an open-source Firecracker microVM platform, and this post is about the part of the problem that is specific to agents: the package name itself is the untrusted input. The companion argument, that installing a package is executing a stranger's code, is covered in Running npm install on untrusted code in a microVM and, for bots holding push tokens, in Your Dependency Bot Runs Strangers' Install Scripts. I will not repeat it here. The question here is earlier: how do you decide whether to install the thing at all, and what do you do with the cases where you cannot decide?

The short version. Treat a package name proposed by a model the way you would treat a URL from an email: plausible-looking is not evidence. Check it against an allowlist or a curated registry proxy first. For names not on the list, ask the registry for age and history signals and hold the young or thin ones for a human. Whatever you do install, install it in a throwaway microVM with nothing worth stealing inside, read back exactly what got resolved (transitive packages included), and kill() the VM. No single layer is sufficient. Name checks catch nothing that was registered in time, and the sandbox does not stop a malicious package from ending up in your lockfile.

Why models invent packages, and why they invent the same ones

A language model produces text that is likely given what came before. An import line is text. from notreal_dateparse_utils import parse is a likely continuation of a prompt about parsing dates, because it follows the naming conventions of thousands of real packages. The model is not looking anything up. It does not know which names are registered on PyPI or npm, and it cannot, because the registry changes daily and the model's knowledge stopped on a fixed date.

The dangerous property is not that models hallucinate names. It is that some of the hallucinated names repeat. Academic work has looked at this directly. The paper usually cited is Spracklen and colleagues' study of package hallucinations in code-generating models ("We Have a Package for You!", presented at USENIX Security 2025). It reported that hallucinated package names were common across the models tested, and that a meaningful share recurred when the same prompt was asked again. I am not going to quote its rates. They depend on the model, the language, the prompt and the date, and any number would be stale before you read it. The qualitative finding is the one that matters: repeatable hallucinations are a target an attacker can aim at.

There is at least one widely reported demonstration. A security researcher at Lasso Security registered a package under a name that models kept recommending, huggingface-cli, as an empty placeholder, and reported that it collected real downloads, including instructions in another company's public repository that told people to install it. It was benign by design. The next one will not be. Verify the details against the original write-up if you plan to cite it. The point for this post is that the attack needs no exploit, no compromised maintainer and no typo. It needs a free registry account and patience.

What changes when an agent holds the keyboard

A human who copies pip install notreal-jsonschema-utils out of a chat window at least sees the name, and might notice it has no homepage. An agent running in a loop removes that pause. It proposes the install, runs it, reads the error if there is one, and moves on. Several things about the loop make it a better target than a person:

  • It retries. When a name does not exist, a common agent behaviour is to try a near variant: notreal_dateparse_utils, notreal-dateparse-util, py-notreal-dateparse. Each variant is another lottery ticket for whoever pre-registered the neighbourhood.
  • It installs quickly. The time between the model writing a name and pip resolving it is seconds, so there is no window in which anyone reads the name.
  • It treats success as proof. If the install succeeds and an import works, the agent considers the problem solved. A malicious package that also does what its name promises is indistinguishable from a good one at that level.
  • It writes the result down. The name goes into requirements.txt, a lockfile or a pull request, so one hallucination in one session becomes a dependency that every later checkout installs on machines that were never sandboxed.
  • It can be steered. A prompt injection in a README the agent just read can tell it to install a specific package. That is not a hallucination, but your defences should not care whose idea the name was.

The last point is why I would frame the whole thing as an input-validation problem rather than a model-quality one. Better models will hallucinate less, and that helps. But the package name is attacker-influenceable input whether it came from a confused model, an injected document or a user's prompt, and the controls below work the same in all three cases.

Why "does the package exist?" is the wrong question

The obvious first defence is to look the name up before installing it. If it is not on the registry, refuse. That check is worth doing, and it is in the code below, but it answers the question that matters least. A name that does not exist is the safe outcome: the install fails. The dangerous name is the one that exists because somebody registered it after the model started suggesting it. Existence is exactly what the attacker supplies.

Other cheap checks have the same shape. Edit distance from popular packages catches typosquats, not inventions, because a hallucinated name is often not close to any real one. It is a new compound of real-sounding words. A check that the name "looks normal" is useless, because looking normal is the model's entire talent. And asking the model whether it is sure is asking the component that made the mistake to grade it.

So the useful framing is: existence tells you nothing on its own, and the registry has better signals than existence. When was the first file uploaded? How many releases are there? Does it link to a source repository that itself has history? Is it on the list of things your organisation already decided to trust? Those answers do not prove a package is safe. They tell you whether this is a name anyone has had time to look at.

The layers, cheapest first

Layer 1: an allowlist or a curated registry proxy

The strongest control is boring. Decide in advance which packages an agent may install without a human, and make everything else a request rather than an action. In a small setup that is a list in the agent's tool code. In a larger one it is a registry proxy, such as a self-hosted devpi or a commercial artifact repository, that mirrors only approved packages, with pip and npm pointed at it via --index-url or .npmrc. A hallucinated name then fails on your proxy, not on the public registry, and the agent cannot install something nobody approved however it spells it.

Two details make this hold up. Normalise names before comparing them. PyPI treats Python_Dateutil, python.dateutil and python-dateutil as the same project (PEP 503), and an allowlist that does not normalise is either too strict or bypassable. And remember that the allowlist covers what the agent asked for, not what pip resolves. A package you approved can pull in a dependency you did not, which is why layer 4 exists.

Layer 2: registry signals for everything not on the list

For names outside the allowlist, ask the registry about the package before anything runs. PyPI's JSON API (https://pypi.org/pypi/<name>/json) returns 404 for a project that does not exist, and for one that does, every release file with its upload time. From that you get the first upload date, the number of releases and the declared project URLs. npm's registry document carries similar information, including per-version publish times. Download counts are not really there: the JSON API's downloads field is a placeholder of -1s, so if you want them, they come from separate services such as pypistats.org or the public BigQuery dataset.

Use these as reasons to hold something for review, not as proof of anything. A package first uploaded last week is not necessarily malicious; every package was new once. But an agent has no business being the first user of a week-old package with one release and no source link, and a human can decide that in ten seconds. The thresholds are policy. Pick them for your risk tolerance, write them down, and expect to tune them. Note, too, that every one of these signals can be gamed by an attacker willing to wait: register early, publish a few harmless versions, add a repository link. Age raises the attacker's cost. It does not make the problem go away.

Layer 3: install in a throwaway microVM

Even an approved install should happen somewhere that does not matter. The argument for why is in the posts linked above, so here is just the shape. Each install gets a fresh Firecracker microVM with its own guest kernel and its own network namespace, restored from a template snapshot (179 ms p50 to create on PandaStack). Nothing inside it is worth stealing: no cloud credentials, no repository write token, no SSH keys, no PandaStack API key. The orchestrator writes the inputs in over the API, reads results back over the API, and kills the VM when it is done. If a package's install hook does something unpleasant, it does it to a disposable machine that is about to stop existing.

A cheap extra here for Python: --only-binary :all: tells pip to refuse source distributions, so no setup.py runs at install time. It will fail on packages that publish only an sdist, which on its own is a mild signal worth knowing about.

Layer 4: limit egress to the registry, where you can

Ideally the install VM can reach your registry proxy and nothing else, so a package that tries to phone home during install has nowhere to call. I need to be plain about what PandaStack does here. On the hosted platform, outbound internet from a sandbox is open by default, with VM-to-VM traffic, the cloud metadata range and the standard mining-pool ports dropped at the host firewall. There is no per-sandbox egress allowlist setting today. Each sandbox does have its own network namespace and veth, so if you self-host you can add default-deny rules with a hole for the proxy in that one namespace. The pattern is in Controlling Network Egress for Untrusted Code. On the hosted platform, the protection is that the VM holds nothing worth exfiltrating, not that it cannot connect.

Layer 5: diff what actually got installed

The agent asked for one package. pip may have installed eleven. The transitive set is where a carefully chosen name can hide something that is not on any list, and it is invisible unless you look. pip can write a machine-readable report of everything it resolved (--report report.json, with name, version and whether each item was directly requested). Read it back out of the VM, compare it to your allowlist, and treat any unapproved transitive package the same way as an unapproved direct one: held for review before the change goes anywhere a real machine will install it.

This is the layer that protects everything downstream. The sandbox contains what happens during this install. It does nothing about the lockfile line that every developer laptop and CI runner will install next week, unsandboxed. The diff is your chance to catch the name before it becomes everybody's dependency.

The gate, in code

Here is a minimal version of layers 1, 2, 3 and 5 for an agent's pip install tool. The gate runs in your orchestrator, never in the sandbox. It normalises the name, checks the allowlist, asks PyPI for existence and history, and only then creates a microVM, installs with source builds disabled, reads pip's report back and kills the VM. Anything that is not a clean allow goes to a human instead of to the agent's retry loop.

python
import json, os, re, urllib.error, urllib.request
from datetime import datetime, timezone

from pandastack import Sandbox

ALLOWLIST = {"requests", "numpy", "pandas", "python-dateutil", "httpx"}
MIN_AGE_DAYS = 90          # your policy, not a magic number
MIN_RELEASES = 3


def normalize(name: str) -> str:
    # PEP 503: case-insensitive, runs of - _ . are equivalent.
    return re.sub(r"[-_.]+", "-", name).lower()


def pypi_facts(name: str) -> dict | None:
    url = f"https://pypi.org/pypi/{name}/json"
    try:
        with urllib.request.urlopen(url, timeout=10) as resp:
            data = json.load(resp)
    except urllib.error.HTTPError as e:
        if e.code == 404:
            return None            # does not exist (yet)
        raise
    uploads = [
        datetime.fromisoformat(f["upload_time_iso_8601"].replace("Z", "+00:00"))
        for files in data["releases"].values() for f in files
    ]
    first = min(uploads) if uploads else None
    return {
        "first_upload": first,
        "releases": sum(1 for files in data["releases"].values() if files),
        "has_repo_link": bool(data["info"].get("project_urls")),
    }


def gate(name: str) -> tuple[str, str]:
    """Return (verdict, reason). verdict is allow | review | refuse."""
    n = normalize(name)
    if n in {normalize(a) for a in ALLOWLIST}:
        return "allow", "on allowlist"
    facts = pypi_facts(n)
    if facts is None:
        return "refuse", "not on PyPI: likely hallucinated, do not retry variants"
    if facts["first_upload"] is None:
        return "refuse", "name registered with no files"
    age = (datetime.now(timezone.utc) - facts["first_upload"]).days
    if age < MIN_AGE_DAYS:
        return "review", f"first upload {age} days ago"
    if facts["releases"] < MIN_RELEASES or not facts["has_repo_link"]:
        return "review", "thin history or no source link"
    return "review", "exists and is old, but not on the allowlist"


def install_in_sandbox(names: list[str]) -> list[dict]:
    sbx = Sandbox.create(template="code-interpreter", ttl_seconds=300,
                         metadata={"job": "agent-pip-gate"})
    try:
        sbx.filesystem.write("/work/requirements.txt", "\n".join(names) + "\n")
        r = sbx.exec(
            "python3 -m pip install --no-cache-dir --only-binary :all: "
            "--target /work/site --report /work/report.json "
            "-r /work/requirements.txt",
            timeout_seconds=240,
        )
        if r.exit_code != 0:
            raise RuntimeError(r.stderr[-2000:])
        report = json.loads(sbx.filesystem.read("/work/report.json"))
        return [
            {"name": i["metadata"]["name"], "version": i["metadata"]["version"],
             "requested": i.get("requested", False)}
            for i in report["install"]
        ]
    finally:
        sbx.kill()   # the VM, its disk and its netns go away here


proposed = ["requests", "notreal-jsonschema-utils"]   # what the agent asked for
verdicts = {p: gate(p) for p in proposed}
blocked = {p: v for p, v in verdicts.items() if v[0] != "allow"}
if blocked:
    print("held for a human:", blocked)
else:
    installed = install_in_sandbox(proposed)
    surprise = [i for i in installed
                if not i["requested"] and normalize(i["name"]) not in ALLOWLIST]
    print("installed:", installed)
    print("transitive, not allowlisted:", surprise)

A few deliberate choices in there. A missing package returns a reason that tells the agent not to try spelling variants, because the variants are what a squatter registers. Nothing is ever auto-allowed just because it is old and exists. Age only moves a name from "suspicious" to "ask a human". The PandaStack API key lives in the orchestrator's environment (PANDASTACK_API_KEY) and never enters the guest. The VM is killed in a finally block, so a failed install does not leave a machine lying around. ttl_seconds=300 is a backstop, not the plan: it is an idle timeout, reset by activity, not a hard lifetime.

The gate checks names, and the sandbox contains one install. Neither of them reviews code. A package that passes every check here can still be malicious, especially one an attacker registered early and aged on purpose. The goal is to make the agent's mistakes cheap and visible, not to certify packages.

What each layer catches, and what it misses

No single layer is sufficient; the misses are why you stack them
LayerCatchesMisses
Existence checkNames nobody has registered yetEvery name an attacker registered first; the main threat
Allowlist or registry proxyAny unapproved name, however it is spelledUnapproved transitive dependencies of approved packages; a compromised approved package
Registry signals (age, releases, source link)Freshly registered squats with thin historySquats registered early and aged deliberately
Throwaway microVMInstall-time damage to the machine doing the installThe package itself landing in your lockfile
Egress limited to the registryInstall-time phone-home and exfiltrationHosted PandaStack: not available as a setting today; self-host only
Installed-set diffUnexpected transitive packages before they shipA malicious package that is on your allowlist

What to tell the agent when it is refused

Refusal messages are input to the model, so write them deliberately. "Package not found" invites the model to try another spelling. Something like "this package does not exist on PyPI; do not try variants; use the standard library or one of the approved packages" points it toward a safe recovery. Giving the agent the allowlist up front, in its system prompt or tool description, also reduces how often it invents names in the first place, because a likely continuation is now one of the names you listed. It does not eliminate them, so the gate stays.

For held packages, the useful behaviour is to stop and ask rather than route around the problem. An agent that cannot install notreal-jsonschema-utils and quietly vendors a copy of something it found on the web has not solved anything. The broader set of guardrails for generated code, including timeouts, resource caps and secret hygiene, is in How to Run AI-Generated Code Safely: a 2026 Playbook.

When this is overkill

  • If your agent never installs anything (a fixed environment, a pre-built template with every allowed package baked in), you do not need a gate. Bake the allowed packages into a custom template with pandastack template build -f Dockerfile -n <name> and remove the install tool entirely. That is the strongest allowlist there is.
  • If a human reviews and approves every dependency change before it merges anywhere, the gate mostly saves them time rather than adding safety, though the sandbox still protects the machine doing the install.
  • If you are scanning packages for malware rather than gating an agent's choices, that is a different job, covered in Sandbox Your AI Agent's Dependency Audit.

For everyone else, the cost is small: one HTTP request per proposed name, a microVM per install, and a report file read back at the end. The alternative is letting a text predictor choose your dependencies at machine speed, with a stranger waiting at the other end of the most likely guess.

faq

Frequently asked questions

What is slopsquatting?

Slopsquatting is registering a package under a name that AI models tend to invent, so that when a model tells a user or an agent to install that nonexistent package, the attacker's package is installed instead. It differs from typosquatting, which relies on humans misspelling a real package name. The term is usually credited to Seth Larson of the Python Software Foundation.

Is checking that a package exists on PyPI or npm enough?

No. A name that does not exist is the safe case, because the install simply fails. The dangerous case is a hallucinated name that an attacker has already registered, and an existence check passes it. Combine an allowlist or curated registry proxy with registry signals such as first-upload date, number of releases and a linked source repository, and hold anything young or thin for human review.

How often do AI models hallucinate package names?

Published research, notably a USENIX Security 2025 study of package hallucinations by Spracklen and colleagues, found that hallucinated package names are common in generated code and that a meaningful share recur when the same prompt is repeated. Exact rates vary by model, language, prompt and date, so treat any specific figure as a snapshot rather than a constant. The recurrence is what makes the names worth registering for an attacker.

Does PandaStack restrict a sandbox's network to the package registry?

Not as a setting on the hosted platform today. Outbound internet is open by default, with VM-to-VM traffic, the cloud metadata range and common mining-pool ports dropped at the host firewall. Each sandbox has its own network namespace, so self-hosted operators can add default-deny rules with an exception for a registry proxy. On the hosted platform, keep the install VM free of credentials so there is nothing worth exfiltrating.

Why install in a microVM if the package already passed the gate?

Because the gate checks names, not code, and a package that passes can still run harmful install-time code. A fresh Firecracker microVM with its own kernel, its own network namespace and no credentials inside means that code runs on a disposable machine that is killed afterwards. The sandbox does not stop the package from reaching your lockfile, which is why you also diff what was installed.

links

Keep reading

more posts

Related posts

  • Safely running pip install from LLM-generated code

    Your agent just decided to pip install some-package and import it. You now run code the model chose, from PyPI, on your host — before you ever hit import. Here's how to make that safe.

  • Private npm and PyPI Mirrors in Front of a Sandbox Fleet

    A container fleet warms up. An ephemeral sandbox fleet cannot, because the whole point is that guest number four thousand is byte-identical to guest number one. That property is worth having and it means you will download left-pad four thousand times unless you do something about it.

  • Isolating AI Agents That Publish Packages

    Your release token is one cat ~/.npmrc away from every postinstall script in your dependency tree. Build in a credential-free microVM, approve the artifact hash, then upload from a second VM that dies afterward.

  • How to Sandbox an Untrusted composer install

    composer install is a build step the way a stranger's USB stick is a file transfer. Scripts and plugins run arbitrary PHP before your app loads a single class — here's how to contain that.

  • Running bundle install on untrusted Ruby code in a microVM

    bundle install doesn't just run scripts — for gems like nokogiri, pg, and bcrypt it invites a C compiler to build attacker-controlled source on your machine. Here's how to make that safe.

More in AI agent sandboxes · See AI agent sandboxes on PandaStack

pandastack

Run code in a microVM in one API call.

50–100 ms cold start. Fork, snapshot, and scale to zero.

measured on the host; your network round trip is extra