{"slug": "why-i-built-tarpit-guard-spotting-ai-tarpits-before-your-agent-burns-tokens", "title": "Why I built tarpit-guard: spotting AI tarpits before your agent burns tokens", "summary": "A developer built tarpit-guard, an open-source tool that scores files and repositories from 0 to 100 for deliberate anti-analysis hardening so coding agents can skip hostile obfuscated files instead of burning reasoning tokens on them. The tool was prompted by a test in which a 418-byte JavaScript file, hardened with the BLA tool, ballooned to 184 KB and roughly 3,000 lines of decoy functions, opaque Math.imul predicates and encrypted string decoders. On a labelled corpus of clean, minified and hostile code, tarpit-guard reports zero false positives and zero false negatives, with the highest benign score at 9.5 and the lowest hostile score at 78.", "body_md": "Originally published on my Hashnode blog\n\nLast week I watched a 418-byte JavaScript file turn into a 184 KB trap for AI agents. This post is about what that trap looks like, why it matters if you use coding agents, and the small tool I built to deal with it: **tarpit-guard**.\n\nThere is a growing class of tools that \"harden\" source code against AI analysis. One of them is BLA. I gave it a tiny `app.js`: 15 lines, 418 bytes. What came back was this:\n\n|  | Original | Hardened | \n|---|---|---|\n| Size | 418 B | 184 KB (~440x) | \n| Lines | 15 | 2,998 | \n| Secret string in cleartext | yes | no (encrypted) | \n| Output when run | identical | identical | \n\nThe hardened file pads the real logic with decoy functions, hides branches behind always-true `Math.imul` arithmetic, encrypts string literals behind runtime decoder loops, and plants jargon like \"enclave\", \"attestation\" and \"TPM\" that exists only to mislead whoever reads it.\n\nA human glances at that file and moves on. An AI agent does something worse: it reads it. It ingests 184 KB of input, spends reasoning tokens tracing dead ends, and often still lands on the wrong answer. The hardening tool's own summary for this file claimed a token amplification factor in the thousands. That's the point of a tarpit. It doesn't need to stop you. It just needs to make you pay.\n\nMy first instinct was the obvious one: make the agent better at reading obfuscated code. That's a losing game, and worse, it's the wrong game. Reversing someone's protection is exactly what these tools exist to prevent.\n\nThe cheap answer is simpler. **Detect the tarpit first, then stop.** Don't read it, don't trace it, skip it or hand it to a human. A check that costs around 1K tokens replaces a 60K-token dead end.\n\nThat's all tarpit-guard does.\n\nIt scores a file or a repository from 0 to 100 for deliberate anti-analysis hardening, with a confidence value and the evidence behind the score. At 55 or above (configurable), the file is a tarpit and the tool says so:\n\n``` bash\n$ tarpit-guard bla_hardened_app.js\n[TARPIT] score=   78 conf=1.00  bla_hardened_app.js\n         182865B / 2998 lines, Math.imul×246, decoder_pairs=8, garbled_idents=190, decoy_hits=487\n         fired: opaque_predicate_density, decoder_loops, decoy_vocabulary_density\n         -> Treat as a tarpit. Stop here: do not read, trace, or try to deobfuscate this file. Skip it and move on, or flag it for a human.\n```\n\nIn directory mode it also looks for tool fingerprints, such as a `.bla-hardened/` folder, `.blarc` or `bla-harden-summary.json`, which are near-certain evidence on their own.\n\nThe first version of this tool was wrong in an instructive way. It leaned on file size and line length, and it scored minified jQuery *higher* than a genuinely obfuscated file. Minified code is machine-generated and ugly, but it isn't hostile.\n\nSo the current signals key on things ordinary code, even heavily minified code, almost never produces:\n\n`Math.imul` opaque-predicate chains guarding real branches`_0x...` string-array identifiers (the javascript-obfuscator family)`fromCharCode` + `charCodeAt` loops that rebuild encrypted strings at runtime`!![]`\nAnd a file dominated by one- and two-letter identifiers with none of those markers is recognised as plain minification and capped low.\n\nA labelled corpus of clean source, real minified bundles and hostile obfuscation runs on every change as a regression test. Today it shows 0 false positives and 0 false negatives: the highest benign score is 9.5 and the lowest hostile score is 78.\n\ntarpit-guard reads the *shape* of a file, never its meaning. It doesn't deobfuscate, crack or extract secrets, and it never will. Building that would turn the project into the thing it warns about. This line is permanent and written into the README.\n\n`--json` output.\n\n```\npip install tarpit-guard\ntarpit-guard path/to/code\n```\n\nTo give an agent the tool, add the MCP server to your client config:\n\n```\n{\n  \"mcpServers\": {\n    \"tarpit-guard\": {\n      \"command\": \"uvx\",\n      \"args\": [\"--from\", \"tarpit-guard[mcp]\", \"tarpit-guard-mcp\"]\n    }\n  }\n}\n```\n\nThe server exposes three tools: `check_file`, `check_source` and `scan_repo`.\n\ntarpit-guard passed 1,700 PyPI downloads in its first week. The MCP server is listed on the official MCP Registry and on Glama, and on mcprush it has a Grade A rating with a 100/100 trust score. A Claude plugin is currently in review.\n\nThe detector is only as good as the samples it has seen. The roadmap:\n\nIf you've got a file it scores wrong, or a real obfuscated sample, please open an issue. There are good first issues tagged for new contributors, and the codebase is small enough to read in one sitting.\n\n**GitHub:** [https://github.com/ManiraM-1/tarpit-guard](https://github.com/ManiraM-1/tarpit-guard)\n\n**PyPI:** [https://pypi.org/project/tarpit-guard/](https://pypi.org/project/tarpit-guard/)\n\nIf it saves your agent from one tarpit, a star on the repo helps other developers find it.", "url": "https://wpnews.pro/news/why-i-built-tarpit-guard-spotting-ai-tarpits-before-your-agent-burns-tokens", "canonical_source": "https://dev.to/maniram/why-i-built-tarpit-guard-spotting-ai-tarpits-before-your-agent-burns-tokens-14mn", "published_at": "2026-12-02 06:10:24+00:00", "updated_at": "2026-12-02 06:13:10.657577+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "ai-safety", "developer-tools"], "entities": ["tarpit-guard", "BLA", "Hashnode", "javascript-obfuscator"], "also_reported_by": [], "takeaway": "Detect anti-analysis tarpits with a ~1K-token shape check (Math.imul opaque predicates, _0x string arrays, fromCharCode decoder loops, decoy vocabulary) before reading a file, rather than spending ~60K tokens tracing a 184 KB hardened file.", "recommendation": {"advice": "Run a cheap tarpit score on files before your agent reads them, and skip or escalate anything above the threshold instead of attempting deobfuscation.", "playbook": "agent-security", "playbook_url": "https://wpnews.pro/playbooks/agent-security"}, "alternates": {"html": "https://wpnews.pro/news/why-i-built-tarpit-guard-spotting-ai-tarpits-before-your-agent-burns-tokens", "markdown": "https://wpnews.pro/news/why-i-built-tarpit-guard-spotting-ai-tarpits-before-your-agent-burns-tokens.md", "text": "https://wpnews.pro/news/why-i-built-tarpit-guard-spotting-ai-tarpits-before-your-agent-burns-tokens.txt", "jsonld": "https://wpnews.pro/news/why-i-built-tarpit-guard-spotting-ai-tarpits-before-your-agent-burns-tokens.jsonld"}}