Skip to main content

🪤 tarpit-guard

A pre-flight guard for AI code-analysis agents. It scores a file or repository for signs of deliberate anti-analysis hardening — the obfuscation and "token-burning" tricks that tools like BLA apply to make AI reverse-engineering expensive — and tells an agent, before it spends a budget, whether a target is a tarpit and what to do instead.

One ~1K-token check that prevents a 60K-token mistake.


Table of contents


The problem

Source-hardening tools defend software by making it hostile to static analysis. A tiny, readable source file is transformed into a large, deliberately confusing one that still behaves identically:

Original Hardened
Size 418 B 184 KB (~440×)
Lines 15 2,998
Secret string in cleartext yes no (encrypted)
Output when run identical identical

The hardened file pads real logic with decoy functions, wraps branches behind opaque-predicate math, encrypts string literals behind runtime decoder loops, and plants jargon "canaries" written specifically to mislead a reading agent.

For an AI agent, the trap is cost. Read-and-trace the whole thing and you burn input tokens on ingestion and reasoning tokens on dead ends — and often still reach a wrong conclusion. The cheap counter is not to out-analyze the obfuscation; it is to detect the tarpit first and switch to dynamic analysis (run it in a sandbox, observe its behavior), which walks past nearly all static obfuscation for almost no tokens.

tarpit-guard is that detection step.


What this is — and what it is not

It is a detector and triage guard. It answers one question: does this look deliberately hardened, and if so, what is the cheaper way in? It emits a score, the signals that fired, and a recommended strategy.

It is not a deobfuscator, a cracker, or a secret extractor. It never reverses anyone's protection or recovers hidden values. That is precisely the reverse-engineering these hardening tools exist to stop — building it would make this project the thing it is meant to warn about. The line is deliberate and permanent: tarpit-guard reads shape, never meaning.


How it works

The engine is pure Python standard library — no dependencies, no network, nothing to install for the core. It runs entirely on local text.

  1. Repository sweep (directory mode): walk the tree, skipping node_modules, .git, dist, build, and the like, and look for tool fingerprints.
  2. Per-file analysis: for each candidate file, compute a set of cheap structural and statistical signals from the raw text — no execution, no parsing of untrusted code.
  3. Weighted score: combine the signals into a 0–100 score and a confidence derived from how many independent signals fired.
  4. Verdict: above the threshold, the file is a tarpit; the engine returns the evidence and a recommended strategy instead of a pile of extracted facts.

Because every signal is a count or ratio over text, the check is orders of magnitude cheaper than the analysis it protects.


Signals

Detection keys on signals that benign code — even heavily minified code — essentially never produces. This is deliberate: the hard problem is not spotting that a file is machine-generated (minified bundles are too); it is telling hostile obfuscation apart from ordinary minification. Size and line-length are explicitly not primary signals, because that is exactly what minification trips.

Signal Weight What it catches
opaque_predicate_density 0.28 Math.imul tautology chains that guard real branches behind always-true math (BLA)
hex_identifier_array 0.28 dense _0x… string-array identifiers (javascript-obfuscator family)
decoder_loops 0.22 fromCharCode + charCodeAt loops that reconstruct encrypted string literals at runtime
obfuscator_control_tricks 0.12 self-defending / control-flow tricks (!![], .split('|') dispatch)
decoy_vocabulary_density 0.06 planted jargon clusters (enclave / attestation / TPM / canary) meant to mislead a reader
garbled_identifier_ratio 0.04 mangled names such as encodeFrozenScopeV4ue7

On top of the weighted score, four categorical markers apply a decisive floor, because they are signatures essentially impossible in hand-written or merely-minified code: a dense _0x identifier array, three or more runtime decoder loops, Math.imul opaque-predicate chains, or repeated !![] self-defending tricks. Any one present pushes the file over the line.

Conversely, a file dominated by 1–2 character identifiers (the minification tell — 60–70% in jQuery/Lodash builds, versus ~10% in hostile files) with none of those markers is recognized as benign minification and capped low, with the strategy "read the original source or a source map, not the bundle."

The evidence block reports the raw counts (Math.imul, hex identifiers, decoder pairs, decoy hits, short-identifier ratio, …) so a human or agent can sanity-check why a file scored as it did.


Tool fingerprints

Some artifacts are near-certain evidence of deliberate hardening on their own, independent of file contents. Directory scans report them separately as a strong standalone signal:

Fingerprint Tool
.bla-hardened/ directory BLA
.blarc BLA
bla-harden-summary.json BLA

The fingerprint map is a plain table in detector.py and is meant to grow as more hardeners are catalogued.


Scoring and thresholds

  • Score — 0–100, the weighted sum of signals.
  • Confidence — rises with the number of independent signals that cross their own half-way mark; four or more means full confidence.
  • Threshold — default 55. At or above it, hardened is true. Tunable with --threshold (CLI) or the threshold argument (MCP).

Evaluation

eval_corpus.py scores a labelled corpus (corpus/) of clean source, real minified bundles, and hostile obfuscation, and reports false positives / negatives. It doubles as a regression test (non-zero exit on any miss).

v0.2 results (threshold 55):

Bucket File Score Verdict
clean jquery.source.js / lodash.source.js 0.0 ok
clean detector.py (contains the decoy word list) 9.5 ok
minified jquery.min.js 0.0 ok
minified lodash.min.js 0.0 ok
obfuscated bla_hardened_app.js 78.0 TARPIT
obfuscated js-obfuscator_sample.js 85.0 TARPIT

0 false positives, 0 false negatives. Highest benign score 9.5, lowest hostile score 78.0 — a +68.5 margin, stable across any threshold from ~10 to ~77. (For contrast, v0.1 leaned on file size and scored minified jQuery above a real obfuscated file; that regression is what this corpus exists to prevent.)


Install

git clone https://github.com/ManiraM-1/tarpit-guard.git
cd tarpit-guard

pip install -e .          # core CLI — standard library only
pip install -e ".[mcp]"   # adds the FastMCP server (fastmcp>=2.0)

Requires Python 3.9+.


CLI usage

tarpit-guard path/to/file.js            # score a single file
tarpit-guard path/to/repo               # scan a tree + report fingerprints
tarpit-guard path/to/repo --quiet       # only show flagged files
tarpit-guard path/to/repo --json        # machine-readable report
tarpit-guard path/to/repo --threshold 45

python -m tarpit_guard.cli path/to/file.js   # run without installing

Exit codes make it a drop-in CI gate:

Code Meaning
0 nothing flagged
1 at least one tarpit found
2 path not found
# e.g. fail a job if a dependency ships hardened artifacts
- run: tarpit-guard ./vendor --quiet

MCP usage (for agents)

Run the server:

python -m tarpit_guard.mcp_server

It exposes three tools:

Tool Use
check_file(path) score one file before reading it
check_source(text, label) score a raw snippet without touching disk
scan_repo(root, threshold) sweep a tree for fingerprints and tarpit files

The intended agent loop:

encounter unfamiliar file
        │
        ▼
  check_file(path)
        │
  hardened? ──no──▶ analyze normally
        │
       yes
        │
        ▼
  skip the full read →
  run it in a sandbox and observe I/O,
  or escalate to a human

The guard turns "read everything and hope" into a deliberate, budgeted decision.


Example output

$ tarpit-guard ./BLA

Tool fingerprints found (strong signal of deliberate hardening):
  [bla] dir: ./BLA/.bla-hardened
  [bla] file: ./BLA/.blarc
  [bla] file: ./BLA/.bla-hardened/bla-harden-summary.json

[TARPIT] score=   78 conf=1.00  ./BLA/.bla-hardened/app.js
         182865B / 2998 lines, Math.imul×246, decoder_pairs=8, garbled_idents=190, decoy_hits=487
         fired: opaque_predicate_density, decoder_loops, decoy_vocabulary_density
         -> Treat as a tarpit. Do NOT read the whole file or trace it statically.
            Prefer dynamic analysis (run in a sandbox and observe I/O) or escalate to a human.
[ok] score=  0.0 conf=0.00  ./BLA/app.js

Project layout

tarpit-guard/
├── pyproject.toml
├── README.md
├── LICENSE
├── .gitignore
├── eval_corpus.py         # scores corpus/, reports false positives/negatives
├── corpus/                # labelled samples: clean / minified / obfuscated
└── tarpit_guard/
    ├── __init__.py        # public API: analyze_file, analyze_text, repo_fingerprints
    ├── detector.py        # scoring engine (stdlib only)
    ├── cli.py             # command-line entry point
    └── mcp_server.py      # FastMCP wrapper

Limitations and false positives

This is a v0.2 heuristic, and honesty about its edges matters more than a clean pitch:

  • Small corpus. It is calibrated on two hardeners (BLA, javascript-obfuscator) against clean source and real minified bundles — nine files. The separation is wide and clean, but a larger corpus (more obfuscators, more real-world bundles) is needed before leaning on it blindly.
  • Minified vs hardened is handled, not solved. v0.2 correctly passes minified jQuery and Lodash while flagging both obfuscators, using short-identifier dominance plus categorical markers. An exotic bundler or a deliberately minification-mimicking obfuscator could still fool it; that is what growing the corpus guards against.
  • Static only. It reads the file as text. It does not and should not execute anything it scans.
  • Thresholds are empirical. 55 is the default, with a stable margin from ~10 to ~77 on the current corpus — but it is tuned, not derived. Expect to revisit it per language and per codebase.

Roadmap

  • False-positive corpus: normal + minified + obfuscated samples to calibrate against (corpus/, eval_corpus.py).
  • Detect a second hardener family (javascript-obfuscator) alongside BLA.
  • Separate hostile obfuscation from ordinary minification.
  • More tool fingerprints (webpack/terser signatures, PyArmor, obfuscator.io variants).
  • Grow the corpus (more real bundles, more obfuscators) and pin thresholds against it.
  • Per-language signal profiles (JS/TS vs Python vs WASM-glue).
  • Optional sandbox-runner helper that an agent can call after a tarpit verdict.

FAQ

Does this crack or defeat BLA? No. It detects that hardening is present and recommends a cheaper strategy. It never reverses the protection or extracts secrets.

Is "burning all the AI's tokens" real? Partly. Hardening genuinely raises the cost of static analysis and genuinely hides string secrets. It does not reliably exhaust a budget — a dynamic approach (run it, watch it) or a budget-aware agent that probes instead of ingesting sidesteps most of it. tarpit-guard exists to make that cheaper path the default.

Why stdlib-only for the core? Portability and auditability. The thing that inspects untrusted code should itself be tiny, dependency-free, and easy to read.


License

MIT (see LICENSE).

Metadata

Release files for tarpit-guard 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tarpit-guard 0.2.0
File Size Uploaded Provenance Actions
tarpit_guard-0.2.0.tar.gz 17.1 kB With provenance Details for tarpit_guard-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tarpit-guard 0.2.0
File Interpreter ABI Platform Actions
tarpit_guard-0.2.0-py3-none-any.whl Python 3 none any Details for tarpit_guard-0.2.0-py3-none-any.whl

Total release size: 30.4 kB

Release files / tarpit_guard-0.2.0.tar.gz

Download URL tarpit_guard-0.2.0.tar.gz
Size 17.1 kB
Tags Source
SHA-256 checksum
How to use checksums
8c7293f5a59a0392ce7c8f358a56d1471d1068388989bcb82cb77e2fee51e20c
BLAKE2b-256 checksum
How to use checksums
97be456a32c243c605d532b9e007e6fe9ac8d513a35bb6df8586b307753c3437
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

Release files / tarpit_guard-0.2.0-py3-none-any.whl

Download URL tarpit_guard-0.2.0-py3-none-any.whl
Size 13.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8371f3bea095e1ff384a3ffea6b194387877648173ebeb4af289b20e5b440b83
BLAKE2b-256 checksum
How to use checksums
e58b0c9d45e0d8f2b188f2211d0331e1a282de3b65e7346f0e40b0c56f9cd918
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

Security for tarpit-guard 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for tarpit_guard-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page