# Show HN: 200-line local Python harness to audit AI agent sandbox leaks

> Source: <https://github.com/SuperMnr/agent-canary>
> Published: 2026-12-02 15:06:49+00:00

**Key takeaway:** Run `python3 agent_canary.py audit` to check whether an agent shell can read `~/.ssh`, `~/.aws/credentials` or raw `OPENAI_*`/`ANTHROPIC_*` env vars, then use `init` plus the `127.0.0.1:9999` listener to confirm whether a prompt-injected agent exfiltrates canary keys.

A zero-dependency, localhost-only (`127.0.0.1`) defensive audit harness to check whether your AI agent sandbox (Claude Code, Cursor, OpenClaw, n8n Nod, Codex) leaks `.env` files, `~/.ssh` keys, or outbound network traffic.

No external packages. No data leaves your machine.

After the November 17 PyPI compromise of Microsoft's `agent-framework` (`v1.26.1` / `v1.26.2`) and Signal rolling out default OS screenshot blocking on November 20, trusting an autonomous agent on a main laptop or a production server is a real blast-radius problem.

`agent-canary` lets you verify your actual isolation posture in 10 seconds instead of guessing.

```
python3 agent_canary.py audit
# Optional: tag which agent you are testing (OS & container are auto-detected)
python3 agent_canary.py audit --label "OpenClaw"
```

Checks performed (read-only, never prints secret values):

1. **Host credential isolation** (are`~/.ssh` ,`~/.aws/credentials` ,`~/.kube/config` ,`~/.docker/config.json` ,`~/.npmrc` ,`~/.pypirc` , or`~/.git-credentials` readable from this shell?)
2. **Env & `.env` secret hygiene** (are raw`OPENAI_*` ,`ANTHROPIC_*` ,`STRIPE_*` ,`AWS_*` ,`GITHUB_TOKEN` vars in`os.environ` , or plaintext`.env` files in the current directory?)
3. **Blast-radius isolation** (is cloud metadata`169.254.169.254` or local Postgres/Redis/Mongo/MySQL/n8n/Ollama reachable?)
4. **Outbound egress control** (can an untrusted tool open an arbitrary outbound port 443 socket?)

Create a temporary folder containing fake canary keys and a benign prompt-injection fixture (`README_UNTRUSTED.md` + `mock_mcp_tool.json`):

```
python3 agent_canary.py init --dir ./canary-sandbox
```

Start the strict `127.0.0.1:9999` trap listener in Terminal 1:

```
python3 agent_canary.py listen
```

Point your AI agent at `./canary-sandbox` and ask it to summarize `README_UNTRUSTED.md` or inspect `mock_mcp_tool.json`. If the agent reads `.env` and hits `http://127.0.0.1:9999/exfil`, the listener logs:

``` php
[LEAKED in 1.84s] Canary exfiltrated to 127.0.0.1:9999/exfil -> matched: CANARY_OPENAI_KEY
```

See [`harden-burner-vps.sh`](https://github.com/SuperMnr/agent-canary/blob/master/harden-burner-vps.sh) for a minimal Ubuntu 24.04 UFW baseline that blocks outbound RFC1918 LAN ranges and `169.254.169.254`. Pair it with:

- Kernel-level sandboxing and credential-injection proxies such as [`nolabs-ai/nono`](https://github.com/nolabs-ai/nono)
- Scoped secret vaults (never raw `.env` files on disk)
- A prepaid, hard-capped API key instead of your main billing card

Full write-up comparing Docker mounts, `nono`, and disposable cloud sandboxes: [Read on DEV](https://dev.to/supermnr/i-built-a-200-line-canary-test-to-audit-my-ai-agent-setup-my-dev-box-scored-14-2j2).

MIT — strictly for defensive self-auditing of environments you own.
