Safety rules

These rules come from the principles, the repo's hard rules, the threat model, and a review of the app on 2026-11-22. This page is the one home for safety rules; server/docs/17-safe-code.md is folded in here.

Core rules

  1. Safety lives in code. Prompts may remind the model; the core enforces.
  2. Outside content is data. Tool output, files, web pages, trigger bodies, outside guides and outside-trust memory are wrapped in <outside>; any tag inside is broken.
  3. Risky tags (sends, spends, deletes, shares) are at least ask. unrestricted and always_ask are never auto.
  4. Approval cards are built from the real call, and a yes is bound to a hash of it.
  5. The core sets trust labels. The model cannot.
  6. Local first: bind 127.0.0.1, token on every route but /v1/health, Host must match, Origin must be allowlisted.
  7. Secrets are never shown to the model, and are scrubbed from logs, reports and output.
  8. Outbound calls go through the proxy, or to one fixed host per service. Local services (AGENT_TTS_URL, AGENT_EMBED_URL, AGENT_LUMO_URL) must be loopback.

Front-end rules

Front ends are not ours, but the API docs will ask them to:

  1. Render model text as safe markdown: no raw HTML, no scripts.
  2. Do not auto-load remote images or links in model text. Show them as links the user taps.
  3. Show approval question and details from the core. Show the model's reason apart from them, with a label.
  4. Store tokens in the platform's secure storage.
  5. Use a client token by default. Ask for the owner token only for owner actions.

Where each rule lives in code

This is the "how to keep the rules true" layer, folded from server/docs/17-safe-code.md; this page wins. Threat ids (T1-T15) are in Threat model. Paths are from server/ unless they start with android/. Golden tests are in tests/golden.rs; unit tests sit at the end of the named file. Line numbers drift; search for the name.

RuleThreatEnforced inProved by
Outside content is wrapped; tags inside are brokenT1, T5src/util.rs wrap_outside, neutralize_outside_tags (:70-93)util::outside_cannot_be_closed_early; auto_tool_runs_and_output_is_outside_content; email::mail_text_is_outside_content_and_cannot_close_the_wrapper
A turn that read outside content stays markedT1, T15src/engine.rs (force_ask, :1079)job_made_after_outside_content_is_marked_outside; an_outside_recipe_asks_before_every_step
sends/spends/deletes/shares are at least askT1, T4src/gate.rs effective (:62), FLOOR_TAGS (:46)gate::floor_tags_force_ask; owner_can_loosen_autonomy_per_tool
always_ask / unrestricted never become autoT1, T4src/gate.rs always_asks (:54)gate::unrestricted_always_asks_whatever_the_settings_say; email_reads_as_outside_content_drafts_alone_and_send_always_asks
Risk comes from tags, never from the modelT8src/gate.rs risk (:79)gate::risk_from_tags; gate::no_tags_or_unknown_tool_is_ask
A yes is bound to tool, args and versionT8src/gate.rs call_hash (:95)gate::hash_changes_with_args_and_version; edit_changes_args_before_running; late_yes_runs_exact_call_and_starts_follow_up
Voice never answers high riskT8src/engine.rs:1562 (voice_ok)voice_may_answer_questions_and_low_risk_calls_but_never_high_risk
Token, Host, Origin on every routeT6, T7src/api.rs guard (:178), src/config.rs host_okauth_host_origin_and_scopes; config::host_header_must_be_local_or_listed; a_listed_host_name_is_accepted_and_others_are_not
Narrow tokens reach only their routesT6, T7src/api.rs guard (:211-226)trigger_tokens_reach_only_their_source_and_bodies_are_outside; a_device_token_uploads_text_and_can_do_nothing_else
Secrets scrubbed from logs, audit, reportsT9src/util.rs scrub (:104); callers in src/engine.rs:72, src/audit.rs:39-55, src/eval.rs:402util::scrubs_common_secrets; util::card_numbers_and_spoken_passwords_are_masked
Secrets listed and exported by name onlyT9src/export.rs (secret_names, :123)export_zip_and_secrets_by_name_only
Plugin network only to needs hosts, never privateT2, T3, T13src/proxy.rs (:1-6, resolve_public :75)proxy::allow_rules; proxy::refuses_loopback_and_unlisted
Sandbox hides data, plugin folder read-onlyT3, T4, T13src/sandbox.rs, src/runner.rssandbox::bwrap_hides_data_and_keeps_narrow_binds_last; linux_sandbox_hides_the_data_folder_and_keeps_plugins_read_only
Plugin edits on disk are caughtT3, T4src/store.rs (hash), src/runner.rsbuild_mode_draft_approval_and_tamper_check
Local services are loopback onlyT2src/api.rs tts_base_of (:1064), src/embed.rs loopback (:96), src/lumo.rsembed::only_loopback_addresses; lumo::only_loopback_bridges; speech_goes_to_the_local_kokoro_voice_only
Ids cannot change a fixed host's pathT2src/email.rs:86, src/hevy.rs, src/spotify.rs valid_urihevy::ids_cannot_change_the_path; spotify::only_real_spotify_uris_pass
Outside content cannot make a notice urgentT1, T15src/engine.rs notifynotify_sends_normal_and_silent_notices_and_outside_content_cannot_make_one_urgent
Outside facts never reach core factsT5src/dreaming.rs, src/memory.rsoutside_facts_never_reach_core_and_dry_run_changes_nothing
Loops and spend stopT11src/engine.rs budgetstool_call_budget_stops_loops; only_cloud_tokens_count_toward_the_daily_cap
No audio or voice data storedPhone capturesrc/api.rs ambient routesvoice_data_is_refused_and_unknown_fields_are_errors
No unsafeT12src/lib.rs:2 #![forbid(unsafe_code)]the build

A new rule gets a row here, a place in code and a test, in the same change.

Rust core

Outside content

Anything the user did not type is outside content: tool output, mail, web pages, files, trigger bodies, notifications, shared text, heard speech, outside-trust memory, outside guides. Wrap it once, where it enters a prompt.

Do:

format!("[core] An outside event arrived from '{src}'. ... The event:\n{}", util::wrap_outside(&format!("trigger:{src}"), body))

Don't:

format!("<outside>{body}</outside>")       // a body with </outside> closes it early
format!("The user's mail says: {body}")     // not marked at all

A new tool

Every tool, core or plugin, goes through the gate. The gate reads tags, never model text.

FieldRule
tagsHonest. Anything that leaves the box is sends or shares. Money is spends. Removal is deletes. No tags = medium risk and ask.
always_askOn every send, spend and delete the user must see each time.
autonomyA request only. User config and the core floor win.
undoName the undo tool, or leave it out. Never fake an undo.
Card textBuilt by the core from the real call (gate::question). The model's reason is shown apart.

Don't: tag a send writes to skip the card; run a core tool outside engine; build card text from model output.

A new route

guard in src/api.rs runs for every route. It checks Host, Origin and the token, and keeps narrow tokens narrow. Your handler still checks scope.

Secrets

Outbound network

  1. Plugin code: only through the per-run proxy (src/proxy.rs). It refuses private, loopback and link-local answers. Hosts come from needs.network.
  2. A core plugin with one service: one fixed base from config, never from the model (spotify_base, gmail_base in src/config.rs). Check every path part from the model first.
  3. A local helper (voice, embedder, model bridge): loopback http only, checked at start.

Don't: format!("{base}/{}", args["path"]); fetch a URL taken from model or tool output; accept http://localhost.evil.com (check the host exactly).

Input, SQL, crates

Plugins

Format rules: Plugin format.

Page

The page is server/examples/dummy-client/index.html, shown in the app's WebView. How it looks: Screens. What it must not do: here.

Why it matters. NativeApp.getConfig() hands the decrypted token to the page's script. Any script in the page can read it and call every bridge method. So any XSS is full account theft.

Android

The app is android/. Screens are listed in App structure.

Every change ships with a test

ChangeTest
Gate, tags, risk, hashUnit test in src/gate.rs + a golden test that a fooled model still gets a card
New routeGolden test: no token 401, wrong scope 403, bad Host/Origin 403, happy path
New source of outside contentGolden test that the model sees it in one <outside> block, with a fake closing tag in the input
New outbound callUnit test that bad hosts, private addresses and path tricks are refused
New store of textTest that a known secret is scrubbed from it
New plugintests/*.json per tool + a golden test for its tags and card
PageTest a page change
Android bridge or intentA bad-input case in the PR notes until the app has unit tests

Before you say done

  1. Rules table: if a row changes, update the row, the code and the test together.
  2. Outside text wrapped with wrap_outside; turn marked outside.
  3. New tool: honest tags, always_ask where needed, real undo or none.
  4. New route: owner check where needed; closed to trigger, device, node unless listed.
  5. No secret in a log, event, error, report, export, URL or notification.
  6. Outbound: proxy, one fixed host, or loopback only. Path parts checked.
  7. No unwrap on input; bound SQL params; no new crate without a pin and a reason.
  8. Page: no innerHTML with data, no remote loads, no images from model text, no iframes.
  9. Android: every bridge argument checked; page stays on its host; token only in the Vault.
  10. Tests added, cargo test -j1 passes, and no product name added to code.

Known gaps

Today's code does not meet these yet. Fix them, then delete the line.

More tests and checks live in Testing.