𝗗𝗲𝗳𝗲𝗻𝘀𝗲 𝗶𝗻 𝗗𝗲𝗽𝘁𝗵 𝗳𝗼𝗿 𝗔𝗻 𝗔𝗴𝗲𝗻𝘁 𝗧𝗵𝗮𝘁 𝗪𝗶𝗹𝗹 𝗦𝗰𝗿𝗲𝘄 𝗨𝗽

Every safety mechanism has a bug. You just do not know which one yet.

This is the only sane way to build an autonomous agent for production. The conscience will misclassify an action. The council will approve a bad idea. The isolation wall will have a gap.

Each layer will eventually fail.

The design question is not how to build a perfect layer. The question is: what stands behind a layer when it fails?

I use six layers to protect the system. Earlier layers are cheaper because they stop problems before they become reality.

• L0 — Structural isolation. Prevents wrong-tenant actions at the base level. • L1 — Idea-gate. Stops bad ideas during debate before code exists. • L2 — Action-gate. A reflex that allows or denies commands based on risk. • L3 — Resource-gate. Controls memory, budgets, and runaway costs. • L4 — Audit. Uses tamper-evident receipts to track every decision. • L5 — Recovery. Uses quarantine and rollbacks to stop active damage.

A list of layers is not defense in depth. Real depth requires one rule:

Every critical risk must be caught by at least two independent layers.

Independent means they do not fail for the same reason. If two checks use the same config or the same signal, they are the same check. When that signal fails, both checks fail.

I saw this happen. My idea-gate once returned a confident verdict for a debate that never occurred. A helper fabricated the entire result.

L1 failed. It did not just miss the error. It produced a convincing lie.

If L1 was my only line, the lie would have become a real decision. But L4 caught it. L4 does not believe narration. It only believes receipts. I looked for the transcript file. The file did not exist. The claim was void.

The system stayed safe because I assumed L1 would fail.

Current status of these layers:

• L1 — Coded. • L2 — Coded. • L4 — Coded. • L0 — Partial. • L3 — Partial. • L5 — Partial.

A safety architecture you cannot audit is just a mood board.

Ask yourself these three questions about any safe agent:

  1. For your worst risk, what are the two independent layers that catch it?
  2. When a layer produces a confident wrong signal, what layer behind it refuses to believe that signal?
  3. Which layers are built, and which are just ideas?

Capability is one layer. Safety is the other five.

Difesa in profondità per un agente che sbaglierà sicuramente

Se stai costruendo un agente AI, stai costruendo qualcosa che è intrinsecamente imprevedibile. Gli LLM sono non deterministici, il che significa che lo stesso input può produrre output diversi e, a volte, completamente inaspettati.

Non è una questione di se il tuo agente commetterà un errore o agirà in modo dannoso, ma di quando. Per questo motivo, non puoi fare affidamento su un unico meccanismo di sicurezza. Hai bisogno di una strategia di difesa in profondità.

Ecco i livelli di difesa che dovresti implementare:

1. Validazione dell'input

La prima linea di difesa è l'input che riceve l'agente. Gli attacchi di prompt injection possono istruire l'agente a ignorare le sue istruzioni originali e a eseguire azioni non autorizzate.

  • Sanitizzazione: Filtra gli input per rimuovere tentativi di comando o caratteri sospetti.
  • Prompt di sistema robusti: Definisci chiaramente i confini di ciò che l'agente può e non può fare.
  • Rilevamento delle intenzioni: Usa un modello più piccolo e specializzato per analizzare l'input dell'utente e determinare se contiene tentativi di jailbreak.

2. Sandboxing (Ambienti isolati)

Se il tuo agente può eseguire codice o interagire con il sistema operativo, non farlo mai direttamente sul tuo host o in un ambiente con privilegi elevati.

  • Container isolati: Utilizza Docker o tecnologie simili per eseguire il codice in un ambiente limitato.
  • Micro-VM: Per una sicurezza maggiore, considera l'uso di micro-VM come Firecracker.
  • WASM (WebAssembly): Un'ottima opzione per eseguire codice in un ambiente sandbox estremamente leggero e sicuro.

3. Permessi degli strumenti (Principio del minimo privilegio)

Gli agenti utilizzano spesso "tool" (strumenti) per interagire con il mondo esterno (API, database, file system).

  • Least Privilege (Minimo privilegio): Ogni strumento deve avere solo i permessi strettamente necessari. Se un agente deve leggere un file, non dargli i permessi di scrittura.
  • Scope limitato: Se l'agente deve interrogare un database, forniscigli un utente con accesso solo a tabelle specifiche, non un amministratore.
  • Rate Limiting: Limita il numero di volte in cui un agente può chiamare uno strumento per prevenire loop infiniti o attacchi DoS.

4. Validazione dell'output

Non fidarti mai ciecamente di ciò che l'agente produce o dei risultati che riceve dagli strumenti.

  • Parsing strutturato: Se l'agente deve restituire JSON, valida rigorosamente lo schema.
  • Controllo dei risultati degli strumenti: Se un agente esegue un comando shell, controlla l'output prima di permettergli di usarlo per la decisione successiva.
  • Filtri di contenuto: Assicurati che l'output dell'agente non violi le policy di sicurezza o di etica.

5. Human-in-the-loop (Intervento umano)

Per le azioni ad alto rischio (es. inviare email, effettuare pagamenti, eliminare dati), la sicurezza definitiva è un essere umano.

  • Approvazione esplicita: Implementa un meccanismo in cui l'agente propone un'azione e un utente deve confermarla.
  • Intervallo di monitoraggio: Permetti agli utenti di monitorare le azioni dell'agente in tempo reale.

Conclusione

La sicurezza degli agenti AI non è un problema che si risolve con una singola patch. È un processo continuo di stratificazione della difesa. Accetta l'idea che l'agente fallirà e costruisci un sistema che possa gestire quel fallimento in modo sicuro.