Sub topic 18
Residual risk and secure defaults
This chapter assumes you know the agent tool loop, indirect prompt injection, and the defenses covered earlier: least privilege, sandboxing, approval gates, egress allowlists, and logging. Here we look at what those defenses leave behind and how to set defaults that fail safely.
Why risk remains
A model cannot reliably separate instructions from data. Every defense in this tutorial limits what an injected instruction can do. None of them stops the model from reading it. So the goal is to reduce the damage, not to reach zero risk.
Each layer also has gaps:
| Defense | Typical gap |
|---|---|
| Labeling untrusted input | The model may still follow text inside the label. It is not a security boundary. |
| Approval gates | Reviewers tire and approve prompts without reading them. |
| Allowlisted commands | An allowed command such as `pytest` can still run attacker-written test code. |
| Egress allowlist | Data can still leave through an allowed host, such as a comment on an allowed site. |
| Sandbox | Anything mounted into it, such as the repository or a token, is still exposed. |
| Logging | It shows an attack after the fact, and only if someone reads the logs. |
Secure defaults
A secure default is a setting that is safe if nobody changes it. Start closed and open up only with a reason.
- Give the agent read-only access and a short-lived token scoped to one repository.
- Run it in a sandbox with no network, then add specific hosts.
- Require approval for writes, network calls, and any command outside the allowlist.
- Do not trust agent configuration files from a repository you have not reviewed. This covers rules files, MCP settings, and hooks.
- Keep secrets out of the agent's environment, so it never holds all three parts of the lethal trifecta at once.
- Log every tool call and keep the logs where the agent cannot edit them.
A default that is safe on a fresh clone of a stranger's repository is the right one. You can loosen it for repositories you control.
Decision rule
Ask what the worst outcome is if the agent follows the most hostile text it will read. If that outcome is unacceptable, remove a leg of the trifecta instead of adding a warning to the prompt. Take away the private data, the untrusted input, or the outbound channel.
Keeping the defaults honest
- Re-run your benign injection tests when you change the model, the tools, or the permissions.
- Review logs on a schedule, not only after an incident.
- Write down what you accept as residual risk, and who accepted it.
Exercise
An agent in CI summarizes new issues. It has a read-only token, no secrets, and an egress allowlist, but it can post comments. Name the remaining risk and one way to reduce it.
Show answer
An injected issue can make the agent post misleading or harmful comments, and the comment is an outbound channel to anyone who can read the issue. Reduce it by having the agent write its summary to a log or a draft that a human publishes, or by limiting comment content and requiring approval before posting.