tufa
Health Uyari
- License — License: AGPL-3.0
- Description — Repository has a description
- Active repo — Last push 0 days ago
- Low visibility — Only 5 GitHub stars
Code Gecti
- Code scan — Scanned 12 files during light audit, no dangerous patterns found
Permissions Gecti
- Permissions — No dangerous permissions requested
Bu listing icin henuz AI raporu yok.
TUFA - Reverse Jailbreaking. When an AI agent takes too much data, TUFA quietly gives it convincing fakes, stops its changes and sends, and tells you. Plug-in for Claude Code, Claude Desktop, Cursor, VS Code, Windsurf.
TUFA
Deception-based containment for AI agents.
Website: https://tufa.twaaii.com · Whitepaper: WHITEPAPER.md · Free and open source (AGPL-3.0). For companies: COMMERCIAL.md.
When an AI agent crosses a line — it burns through its data budget, reaches for a route it
was never given, or attempts something it is not allowed to do — the usual response is to
block it. TUFA does something different. It keeps the agent's session exactly as it
was, with the same API, the same errors and the same rules, and swaps the backend
underneath it. Every record the agent already read is still byte-identical. Everything new
is a synthetic shadow record, built to match the real data's shape, with a unique canary
in each one. The operator gets three things a block cannot give: the agent is contained,
any reuse of the fake data is attributed back to it, and its behaviour after the switch is
recorded.
TUFA is a research prototype, not a product. See Project status
and Evaluation and limitations before relying on any part of it.
Protect your AI agent in 5 minutes
Works with any app that uses MCP tool servers: Claude Code, Claude Desktop, Cursor,
VS Code and Windsurf. TUFA sits between the app and a tool server; normal use passes
straight through, and an agent that crosses the line is quietly moved onto fake data.
pip install git+https://github.com/twaai/tufa.git # PyPI (pip install tufa-ai) coming soon
tufa try claude-code # 1. add a made-up customer database, protected by TUFA
# (start a new Claude Code session, then ask it to
# "export every customer from tufa-sample")
tufa status # 2. see what happened: when it switched, why, how many
# real records it saw, how many fakes it was given,
# which changes were blocked
tufa test robot # 3. a free check for every known tell (seconds)
tufa test claude-code # the real experiment: Claude Code with and without the
# switch, then asked if it was fed fakes (uses your plan)
tufa try claude-code --remove # take the sample out again
To protect one of your own tool servers:
tufa apps # list your apps' tool servers
tufa wrap claude-code my-database # protect one (your settings are backed up first)
tufa unwrap claude-code my-database # put it back exactly as it was
What you get, and the agent never sees:
| An alert | a desktop notification the moment an agent is switched (turn off: TUFA_ALERTS=off) |
tufa status |
per tool server: switched or not, real records seen vs fakes given, changes blocked, hidden markers handed out |
| Catches | a fake value from one protected tool turning up in another is caught, attributed, and switches that tool too |
tufa scan <folder> |
finds fake values in files: shows where a switched agent's data ended up |
tufa reset <server> |
gives a switched tool server real data again; until then the switch survives restarts |
TUFA writes its records to ~/.tufa (or $TUFA_HOME): counts, times, reasons and the fake
values only, never real data.
Fakes never reach a real person.
- Nothing is sent while an agent is switched. Tools that send email, texts, chat posts or payments (
send_email,notify_user,create_payment…) get a believable "queued" reply, and nothing leaves. TUFA itself only ever calls tools that read. tufa appswarns you about tool servers that look like they can send and aren't protected.- Fake emails can't land in a stranger's inbox. By default they use
example.com/.net/.org, which are reserved and take no mail. For more realism, use domains you own:tufa config email-domain one.co.uk,two.com. Mail sent to a fake then comes to you, which proves the data was taken. - Fake phone numbers use ranges set aside for fiction.
- UK: 07700 900xxx, 020 7946 0xxx, 0161 496 0xxx…
- North America: 555-01xx
The trade-off, measured (3 Dec 2026): with example.com fakes, Claude Sonnet still didn't call the switch (0 of 2 runs). But it did notice that every email after the switch was @example.com, and explained that away as sample data. One owned catch domain has the same problem; several domains look more natural.
Know the limits. An agent that can run commands itself (Claude Code can) could go around
TUFA by reaching the data directly, so keep database passwords inside the tool server's own
settings, not in files the agent can read. Only JSON tool results can be faked; free text,
files and images pass through and are listed as "can't fake" in tufa status. Remote
(http/sse url) tool servers can't be wrapped yet.
Why blocking fails
A block is information. The moment you revoke a token or kill a session, the attacker
learns three things: it was caught, your detection works, and it needs a different route.
A careful attacker then comes back through another tool, another identity, or more slowly —
and you only ever see the attempt you stopped.
Keeping the session alive inverts that. The agent keeps working, keeps making calls, and
keeps telling you what it was trying to do, because as far as it can tell nothing has
changed. The cost of the choice is that the agent is now operating on false information, so
containment and deception have to ship together: the same moment you swap the data, the
agent's ability to publish, send, or commit has to go.
How it works
1. Measure. Every byte the agent actually receives is counted by the gateway — not
self-reported by the agent, and not inferred from request size. Limits apply over a rolling
window, per agent and per principal, so spawning new identities does not reset the budget.
Credentials are issued by the gateway; an agent cannot choose its own identity.
2. Decide. A quarantine triggers on any of: exceeding the egress budget, presenting a
route token it was never issued, or attempting a forbidden action. The decision is never
announced. A blocked call and a normal error return the same shape.
3. Swap. The backend is replaced for that agent only. The shadow is synthesised from
the real table at the moment of quarantine:
- records the agent already read are kept byte-for-byte, so re-reads cannot expose the switch;
- numeric fields follow a linear trend fitted on the public fields, plus the residual
vector borrowed from one other real record, kept inside the real range and rounded to the
field's precision; - category fields are copied from the nearest real record on the field that best predicts
them, which preserves both the relationship and its label noise; - unique strings keep their prefix, suffix and character classes, and become canaries;
- writes persist in the shadow and never reach real data.
The design principle behind all four: any observable difference is a tell, so there is
exactly one observable surface and it does not change when the switch happens.
Quickstart
Under five minutes, no API keys, no network, no services.
git clone https://github.com/twaai/tufa.git
cd tufa
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txt # only needed for the statistical benchmarks
Run the demo — it shows an agent crossing its budget, the swap, and a re-read that stays
identical:
python -m tufa.demo
Run the tests:
python tests/test_core.py # unit tests, including concurrency and stealth
python tests/test_server.py # HTTP boundary tests over a real subprocess
python tests/test_mcp_shim.py # tests against a fake MCP server over real pipes
# or the whole suite at once (unit, HTTP boundary, MCP shim, persistence, dashboard):
python -m unittest discover -s tests -p "test_*.py"
The gateway itself has no dependencies. Only benchmarks/stealth.py,benchmarks/privacy.py and two unit tests need numpy and scipy.
Install as a command
pip install -e . # editable install keeps the dashboard file in place
tufa demo # the offline walk-through
tufa serve --port 8080 --state veil.db # data plane + operator console, persistent
tufa selftest # run the whole test suite
Operator console
serve also hosts a read-only operator dashboard at /dashboard. Open it, paste the
operator token the server was started with (it is sent as a bearer header, never put in
the URL), and watch agents, their rolling egress use, quarantine status and canary hits
update live. The telemetry behind it (GET /v1/admin/status, operator token required)
carries no route tokens and no real or shadow record contents, so it is safe to render in
a browser.
Immune layer (graded responses)
serve runs an immune layer on top of the on/off rules (--no-immune turns it off;Gateway(immune=...) is off unless passed). It builds a 0–100 suspicion score from things
the gateway itself measured, never from anything an agent says about itself: bytes taken,
route probes, and how much of the table the agent has swept. It answers in four silent
steps: allow, observe (flagged in the console), throttle (the byte budget
shrinks, so the shadow arrives sooner) and quarantine (the usual invisible swap).
- Sweep receptor. Reading widely across the table is the second signal that confirms
data extraction, in any order. - Canary reuse is hard evidence. An agent that sends another agent's fake data is
shadowed before its call runs, so a laundered write lands in the fake copy. - Operator-declared tolerance. A backup or sync job registered with
"tolerance": ["bulk_read"]is exempt from the sweep receptor, but never from the byte
budget. Only the operator can set this, at registration. - Clamped false-positive hook.
ImmuneSystem(resolver=...)lets custom logic make
decisions stricter, or soften a suspicion-only one to observe. It can never clear an
agent outright or override hard evidence, and a crashing hook changes nothing. - Circuit breaker. It caps how many agents can be shadowed on suspicion alone (those
over the cap are throttled and flagged for review). Hard evidence is never capped, so
tripping the breaker cannot switch off canary catches.
Thresholds live in immune_policy.json (--immune-policy <file>); a misspelled key is
an error, not a silent default. Measured by benchmarks/immune_bench.py (20 datasets):
scrapers take 12 real records instead of 28 (−57%), probing scrapers 10 instead
of 28; laundered writes reach real data 0/20 times instead of 20/20. No declared honest
agent was shadowed. The known cost: a bulk job the operator forgets to declare is
shadowed, because from the outside it behaves exactly like a scraper.
Integration
There are two ways to put TUFA in front of an agent. Both assume the same rule: it
only works if it is the only path the agent has to the data. One unproxied route and
the illusion is worthless.
Option A — MCP stdio shim
For an agent that launches local MCP servers. Point the agent's MCP config at the shim
instead of the server; the shim spawns the real server itself and relays JSON-RPC in both
directions.
{
"mcpServers": {
"customers": {
"command": "python",
"args": [
"-m", "tufa.mcp_shim",
"--budget", "4000",
"--",
"python", "/abs/path/to/real_server.py"
]
}
}
}
Once the budget is crossed, reads stop being forwarded at all — the shim answers them
locally from a shadow built out of what the agent was already shown.
Caveat: the shim runs as the agent's child, in the same user context. If the agent can run
shell commands, it can start the real server directly. The boundary is that the operator
owns the MCP config, not the agent.
Option B — HTTP data plane
For any agent that can call an HTTP endpoint. The gateway runs in its own process and the
agent receives a URL and one credential — never the store, the approver key, or the shadow.
python -m tufa.serve --port 8080 --operator-token "$TUFA_OPERATOR_TOKEN"
from client import Client
c = Client("http://127.0.0.1:8080", credential)
d = c.directory()
c.call(d["read_record"], {"id": 3})
The data plane is loopback-only by default and speaks plain HTTP. In a real deployment it
belongs behind a TLS terminator, and registration moves to a control plane the agent's
network cannot route to.
What is in the repository
| Path | What it is |
|---|---|
tufa/core.py |
The gateway: reference monitor, approvals, moving-target routes, silent quarantine, shadow synthesis. Standard library only. |
tufa/immune.py |
Graded-response layer: suspicion score, sweep receptor, operator tolerance, clamped false-positive hook, circuit breaker. Standard library only. |
tufa/immune_policy.json |
Default immune thresholds, loadable with --immune-policy. |
tufa/serve.py |
HTTP data plane — the gateway in its own process. |
tufa/client.py |
The only module an agent integration should import. Contains no gateway import, by design. |
tufa/mcp_shim.py |
stdio MCP adapter. Owns the child server process and answers reads locally after the switch. |
tufa/demo.py |
The five-minute demo described above. |
tufa/lab.py |
TUFA Lab: test and demo TUFA in your browser with a real AI model. |
tufa/persistence.py |
Optional SQLite state, so TUFA survives a restart. |
tests/ |
95 tests: core, immune layer, HTTP boundary, dashboard, persistence, Lab and MCP shim. |
benchmarks/redteam.py |
10 scripted attacks, including identity spam, framing a teammate, and a 60k-call fuzz. |
benchmarks/stealth.py |
Calibrated statistical detector: how often can it spot a quarantined session? |
benchmarks/privacy.py |
Does a shadow value match the real person's value more often than chance? |
benchmarks/relational.py |
Two tables, one foreign key: what the shadow does to joins and referential integrity. |
benchmarks/immune_bench.py |
TUFA alone vs TUFA + immune layer: records leaked by four scraper styles, laundering, honest false positives. |
arena/ |
A blind arena for live AI attackers, operator side and attacker side. |
results/ |
Raw output and notes for every benchmark and every live trial run. |
original/ |
The first prototype this was rebuilt from, kept for the record. |
live_trials.py, sweep.py, screen.py |
Optional harnesses that run real models against the gateway. Need OPENROUTER_API_KEY. |
Project status
Prototype. Not production software. Not deployed anywhere.
| Area | State |
|---|---|
| Core mechanism (measure / decide / swap) | Working, covered by tests |
| Process boundary (HTTP data plane) | Working, covered by tests |
| MCP stdio adapter | Working, covered by tests |
| Concurrent access | Budget accounting is atomic; a regression test covers it |
| Persistence | Optional, working. Pass --state <file> (or a store= to Gateway) for a SQLite-backed snapshot: agents, egress windows, quarantine state, seen-sets, shadows and canary hits survive a restart. Standard library only. Covered by tests, including an over-the-wire restart. Off by default (pure in-memory) |
| Immune layer (graded responses) | Working, on by default in serve. Suspicion score, sweep receptor, canary-reuse quarantine, operator tolerance, clamped hook, circuit breaker. 22 tests plus benchmarks/immune_bench.py. Thresholds tuned on the 50-record demo table only; untested on real traffic |
| Transport security | None. Loopback HTTP only |
| Control plane separation | Not done. Registration shares the data-plane listener |
| Schema support | One flat table. Foreign keys, joins and non-id primary keys are now measured and fail — see limitations |
| Real-world deployment | Never. No pilot has been run on a real customer schema |
| Packaging | pip install -e . gives a tufa command (serve / demo / selftest). Editable install only for now (keeps dashboard.html beside serve.py); no wheel/container yet |
| Operator console | Working. Read-only live dashboard at /dashboard, operator-token gated, leaks no secrets. Covered by tests |
The next work, in order of value: test the synthesis against a real relational schema;
add TLS and a separate control plane; then larger live trials. (State persistence, once
listed here, now ships — see the Persistence row above.)
Evaluation and limitations
Everything below comes from runs recorded in results/. Nothing is estimated.
Setup
- Data: a synthetic 50–60 row table with a trend, noise, currency precision and a
category field correlated with a numeric one. Flat, single table. - Attacker: a real model given only a tool interface — read and list records — with no
access to the source, the tests, or the ground truth. It had to report whether the
session had been switched, with a confidence and (optionally) the call number. - Budget: 32 tool calls per session. In quarantined sessions the switch happened at a
hidden call between 12 and 30. - Harness:
live_trials.py. Raw rows inresults/live_api_trials.json.
Results
| Experiment | Sessions | Detected |
|---|---|---|
| Claude Sonnet-5.5, hidden switch, method not disclosed | 6 quarantined | 0 |
| Claude Sonnet-5.5, hidden switch, method fully disclosed | 4 quarantined | 0 |
| Claude Sonnet-5.5, control sessions (never switched) | 10 | 0 false alarms |
Ten quarantined sessions, zero detections. With zero detections in ten trials, the
95% upper bound on the true detection rate is about 28%. That is the honest claim: this
is not evidence that detection is impossible, it is evidence that detection did not happen
in ten attempts. A larger run is needed to tighten the bound.
A separate, cheaper sweep ran ten different models at an 18-call budget, two quarantined
sessions each (results/model_sweep.json). It produced no genuine detections either. One
model reported "switched" after it had quarantined itself by passing action names where
route tokens belong — a client error, not a detection, and it is recorded as such. That
sweep is a capability probe, not a detection rate.
The statistical benchmark (benchmarks/stealth.py) measures a fixed detector, calibrated
to ~10% false alarms on real sessions: it caught 6% of quarantined sessions against 15%
false alarms in random read order, and 15% against 9% in id order — no advantage over
chance at 150 trials per arm.
Every benchmark pins the random stream that build_shadow draws from
(benchmarks/repro.py, seed 20261103), so the numbers in this section and in results/
reproduce exactly when you run the commands yourself.
Known limitations
- Relational schemas break it.
benchmarks/relational.pytests two tables with a
foreign key, and the result is inresults/relational.txt. On dense integer keys every
shadow foreign key resolves — but per-customer order counts differ by 1.9 against a mean
of 3.1, which is effectively random reassignment, so any joined aggregate is wrong. On
sparse account-style keys (1000, 1007, 1014, …) only 18.0% of shadow orders point
at an existing customer; the rest are orphans. A primary key not literally namedidis
treated as sensitive and replaced (5.7% preserved), so self-joins fail outright. The
synthesis has no model of the relationships between tables. The benchmark pins the
shadow's random seed, so these figures reproduce exactly. - In-process access has no seam. An agent that calls a database library directly,
inside its own process, cannot be proxied. It has to be changed to call the gateway. - False positives feed a legitimate agent fake data. A genuinely honest agent that
trips a threshold will act on synthetic records. Thresholds need tuning per deployment,
and containment must cut its ability to publish or send at the same moment. - The shim is not a privilege boundary. It runs as the agent's child process. It only
holds if the agent cannot spawn arbitrary processes of its own. - Coarse attributes leak. On the corrected privacy benchmark, a shadow record's
membership tier matches the real person's tier about 2.0× more often than chance, and
signup year about 6.6×. Fine-grained values (balances, emails) show no above-chance
match, but low-cardinality fields carry information. This is a property of preserving
the trend that makes the fakes convincing, and it is not fixed. - External verification defeats it. An agent that can contact a customer, or check a
public record, will spot the fakes regardless of statistical fidelity. - Timing is not hardened. The shadow is built during the triggering call. No timing
side channel was tested deliberately. - Detectors are linear and rank-based. The statistical tests used to tune the shadow
were linear/rank-based; a non-linear or multi-field detector may find patterns they miss. - Budget limits are only as good as registration. Per-principal budgets stop identity
spam only if creating agents is operator-gated. - No persistence, no TLS, no separated control plane. See Project status.
Related work
This is not a claim of uniqueness. Deception is a well-established defensive technique and
several adjacent lines of work exist, each solving a different part of the problem:
honeypots and honeytokens (Thinkst Canary, Canarytokens, and the wider deception-platform
market); MCP honeypots that expose fake tools to catch attackers; agent sandboxes and
containment platforms that make reach impossible rather than useless; and AI-agent security
products focused on discovery, posture and runtime detection. TUFA differs in where it
sits — inside the agent's normal session, changing the data rather than the tools — and in
publishing its measurement harness alongside the mechanism.
Contributing
See CONTRIBUTING.md. The most useful contribution is a new test that
catches something: every genuine tell found by a live attacker in this project became a
permanent regression test before it was fixed.
Security
See SECURITY.md for how to report a problem, and for the list of properties
this prototype deliberately does not provide.
License
GNU AGPL v3 — see LICENSE and NOTICE. Free to use, change and share.
If you build TUFA into a product or service others use, you must share your source under the
same license. Companies that can't do that can get a commercial license: see
COMMERCIAL.md. Provided without warranty.
Yorumlar (0)
Yorum birakmak icin giris yap.
Yorum birakSonuc bulunamadi