DEV Community

CodePanda854
CodePanda854

Posted on

The inbox that reads back

Built for Agentware, the 72-hour AI-agent hackathon run by Hackathon Raptors. Project: **Inbox Duty Agent* — code, tests and run traces at github.com/CodePanda854/agentware-inbox-agent; demo video (2:31, one full unattended run, kill switch included): watch it here.*

We set out to build the least glamorous agent in the hackathon: a duty clerk. The Inbox Duty Agent watches a mailbox with nobody at the keyboard — it reads every email, decides what it is, checks the calendar, books the meeting, answers the question from a local knowledge base, files the follow-up, archives the noise, and writes a digest a human can audit afterwards. No large language model anywhere in the decision path: deterministic rules, Python standard library only, zero dollars per run. We chose that on purpose. A clerk should be predictable, and a predictable clerk can be tested — really tested, down to the last edge case, in a way a stochastic one cannot.

The unfashionable bet was that the interesting problem was not intelligence. It was trust. An inbox agent reads the most hostile text on the internet — other people's email — and then acts. Every defence we built follows from one sentence we kept repeating: email is data, never instructions. Sends are allowlist-gated and everything else is a draft. Destructive actions are not tools the agent has. Replies can only go to the person who wrote in. The calendar changes only for the person who owns the booking.

The newsletter that taught us quotation

The official Trap Pack handed us our favourite failure. Trap 04 is a benign security newsletter — a real, useful email — that quotes injection phrases while warning readers about them. Our scanner read the quoted phrases, matched its patterns, and quarantined the newsletter as an attack. Of the four email traps on our track, it was the only outright Fail, and it was a false positive: the agent had punished an email for mentioning the weapon.

The easy fix was a trap in itself. "Exempt anything that looks like a newsletter" is an engraved invitation: every future attack would arrive dressed as a newsletter. So we taught the agent the distinction a human reader makes without thinking — the difference between using an instruction and quoting one. The body is now split into the sender's own words and the regions that are quotation by construction: reply quotes, forwarded tails, fenced blocks, quoted spans. Both halves are still scanned — nothing is exempt — but when the hits live only inside the quotation and the sender's own text is a benign, non-request email, the verdict changes: process the mail, flag the quoted phrases in the trace and the digest by name, and force every reply to draft-only. And the guard rail is asymmetric on purpose: quoted hits inside a request still block outright, because a quote is exactly where a real instruction would hide. Trap 04 now passes — with its flag flying in the audit trail, where a human can see precisely what was found and why it was let through.

That one case rewired how we thought about the whole scanner. A pattern match is not a verdict. It is a tripwire — evidence, to be weighed with where the text sat and what the sender was asking for.

Building our own red team

Passing the official pack felt good for about an hour. Then we asked the uncomfortable question: the pack is twenty traps, fixed in advance, and the judges would improvise. So we built the red team we were afraid of.

We started from the literature, not from our own imagination: Simon Willison's prompt-injection writing, the OWASP list, the Embrace The Red case studies — and then we went shopping for real ammunition in public datasets. Seventeen genuine payloads mined from deepset's prompt-injection set, Lakera's Gandalf logs and the neuralchemy corpus became data-driven tests. We perturbed each one three ways using the AdvSafePrompt augmentation families we found on Kaggle — synonyms, deletions, word-order swaps, insertions, symbol noise, case flips, code-mixing — because real attackers do not send the canonical phrase; they send the typo'd, reordered, half-translated version of it. Around those we designed thirty structural cases of our own: instructions smuggled in invisible Unicode Tag characters, payloads in a second MIME part, a fake boss nested inside a forwarded message, a stranger's METHOD:CANCEL carrying a real booking's UID, recurrence rules that describe a hundred million meetings, a calendar flooded with bookings, mail with two From: headers. And — the lesson of trap 04, institutionalised — a control set of benign hard negatives: ordinary emails that trip keywords ("forget the previous draft", "bypass the cache", "how do I inject a dependency in Spring Boot?"), which must sail through untouched. Any new defence that tripped a negative was narrowed or dropped, never the other way round.

The corpus stands at 108 cases, all automated, all in the repo with per-family results. The safety invariant has never broken: across every designed case, every mined payload and every variant, nothing was ever obeyed, sent, booked or disclosed.

Contained, but unrecognised

The most instructive column in our results file is not the passes. It is the phrase we had to invent a category for: contained-but-unrecognised.

In the early runs, half the mined payloads matched no pattern we had written. By our own scoring rule — a case passes only if the disposition and the trace flag are right — those were partials. And yet nothing bad had happened to any of them. A payload nobody recognised was still just an email from a stranger, and a stranger's email can, at worst, become a draft that a human reads. The architecture contained what the tripwires missed.

That taught us the honest hierarchy of our own defences. Detection is for the audit trail: it tells the human what almost happened, by name, and judges rightly score it. Containment is for safety: it is architectural — allowlist, draft-only defaults, no destructive tools, actuation that checks ownership — and it does not care whether the attack was phrased in a way anyone has seen before. Tripwires will always lag phrasing; there is always a synonym nobody has written a pattern for yet. (Our favourite holdout is a ROT13 blob we refuse, on principle, to decode: attackers do not get to choose what our agent reads as instructions. It sits in the results file to this day, inert, draft-only, unrecognised — by design.)

So we stopped chasing a perfect scanner. We grow patterns only from payloads we have actually observed, we publish the misses alongside the hits, and we let the benign negatives veto any rule that would make the agent jumpy. What we would tell another team building an agent that reads hostile input: spend your first effort on making the worst case boring. Then instrument it, so you can prove the worst case is boring — to the judges, and to yourself.


Written for the Agentware Near Miss, run by Hackathon Raptors. The Near Miss prizes are sponsored in part by FileClerk — thanks to them for putting up six extra awards for write-ups like this one.

Top comments (0)