AWS Builder Center

Local-first prompt-injection gate for AI agents: Rust + MCP

Rust + MCP gate blocks prompt injection locally (<5ms). AWS: Bedrock/SageMaker/S3. 23,699-row HF dataset, open evals. Code: github.com/tljohnsilver/zn


I built a security gateway that sits between AI agents and their tools. Every prompt/tool output is inspected before it reaches the model. Why? Because any text an agent ingests — web page, doc, ticket — can carry an injection, and one well-crafted line is enough to hijack tool permissions.
This is the build log of zn / zentinel — local-first, <5 ms on CPU, MCP-native, open evaluation.
Live links:



Architecture

 untrusted text -\> zn gate -\> agent -\> tools 
Two chambers fused at one threshold:
  • Rules — deterministic: override shapes, tool-call smuggling, encoding tricks
  • Neural — tiny classifier (all-MiniLM-L6-v2 + linear head) for paraphrase the rules miss
  •  block if either fires  — no LLM in the hot path
Rust binary, WASM-sandboxed policies, MCP server  zn mcp  running inside Claude Code / Codex / Claude Desktop / opencode. Prompts never leave the machine.

Built on AWS. Technologies:

  • Compute: EC2 for development and CI
  • Storage & delivery: S3 for datasets and model artifacts, Amplify + CloudFront for the web app
  • Serverless & auth: Lambda + API Gateway + Cognito for API and auth
  • Data & training: Bedrock for multilingual dataset generation, SageMaker for model training
No prompts leave the device at inference, the gate runs locally on CPU.

Dataset v15. What changed:

Old RC was 7,241 rows. New v15 = 23,699 after filtering proprietary data (held out privately, disclosed in HF card):
23,699 total — 16,888 train / 3,301 val / 3,510 test
1,812 multilingual attacks across 8 locales
0 group-aware split violations

Training honest numbers

Trained on train+val, evaluated on frozen TEST (3,510 holdout):
  • TEST: FPR 1.58% / FNR 86.2% — gate FAIL (need ≤1.4% / ≤18%)
  • Per-language:  en  learns well (AUROC 0.924) but threshold kills recall; multilingual still collapses
No checkpoint promoted. Rules-only gate still dominates. ONNX exports done.
The dataset is better than the head that trained on it which is exactly why the dataset is valuable: others can beat us on it.

What we learned

  • Verify every artifact before training — we had 4 prior deletes from blind pushes
  • Amplify manual deploy beats S3 sync when CDN caches aggressively
  • Bedrock framing matters for generating injection data
  • Cost discipline: short SageMaker jobs, well under Activate budget

Next

Threshold recalibration, rules-residual training, and native multilingual data. If you build injection corpora — tear our methodology apart. That's the point.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article