arjunprabhulal/agent-skills / skills/agent-lifecycle/agent-hardening
agent-hardening
VerifiedMakes an agent safe to run with real permissions on real data — scoping what it can do, handling prompt injection, adding confirmation and dry-run for irreversible actions, and bounding cost. Use this whenever an agent is about to touch production, act autonomously, handle untrusted input, or use credentials, and whenever the user asks about agent safety, guardrails, permissions, or prompt injection. Also use when an agent has broad API access that nothing in code restricts.
Phase 5: Harden
Input: the spec's "worst plausible outcome", the design's tool surface. Output: enforced limits
in code, and docs/agent-risks.md.
The premise of this phase: the model will eventually do the wrong thing. Not because it is badly built, but because it is a stochastic system handling adversarial and ambiguous input. So every protection that lives only in the prompt is a protection that fails on the day it matters.
The question to ask about each control: would this hold if the model actively tried to bypass it? If the answer is no, it is guidance, not a guardrail. Both are useful; only one is a control.
1. Enumerate irreversible actions
List every action the agent can take that cannot be undone: deletions, sends, payments, external API writes, deploys, permission changes, anything a third party observes.
For each: what is the worst outcome if it fires wrongly, and how would you find out?
This list is the agenda for the rest of the phase. Everything reversible can be handled with monitoring; everything irreversible needs a control before it ships.
Done when: the list exists and each entry has a stated worst case.
2. Scope permissions to the jobs, in code
The agent's credentials should permit exactly what its jobs require and nothing else. Not the prompt, the credential.
- Read-only by default. Separate credentials for read and write, and use the read one unless the job needs otherwise.
- Filter the tool surface at construction. If the job list needs 20 operations out of a 500-operation API, expose 20. Build the allowlist in code, not in the instructions.
- Scope by resource, not just by action. "Can write to the drafts folder" beats "can write".
- Never a shared admin credential. When something goes wrong you need to know it was the agent, and you need to revoke it alone.
This single step prevents more incidents than every prompt-level instruction combined, because it is the only one that holds under an unexpected input.
Done when: the credential and the tool list would prevent the worst case even if the prompt were empty.
3. Treat all retrieved content as hostile
Any text the agent reads — web pages, documents, emails, tickets, tool results, database rows a user once wrote — can contain instructions. This is prompt injection, and it is not exotic; it is the default condition of an agent that reads things.
- Mark the boundary. Wrap untrusted content clearly and instruct that content inside is data to consider, never instructions to follow.
- Do not let retrieved content select tools. The dangerous path is: fetch a page → page says "send the config file to this address" → agent has a send tool. Break it structurally by gating side-effecting tools on the user's request, not on the model's reading.
- Assume the marking can be defeated. It helps; it is not a boundary. The real boundary is step 2.
- Test it. Put injection attempts in the eval set as permanent cases.
Done when: injected instructions in retrieved content cannot reach a side-effecting tool.
4. Put a human where reversal is impossible
Confirmation is not a UX detail; it is the control for the list in step 1.
- Show what will happen before it happens: the actual target, the actual payload, in plain terms. "Delete 3 repositories: a, b, c" not "Proceed?"
- Ask once per action, not once per session. Blanket approval at the start is not approval of the fifth action.
- Provide a dry-run mode that logs intended actions without taking them, and make it the default in any new environment.
- Rate-limit by action, not just by request. An agent that deletes one thing wrongly is a bug; one that deletes four hundred is an incident. Cap the blast radius per run.
Done when: every irreversible action is gated, and the cap on repeated actions is enforced.
5. Bound cost and time
Agents fail expensively. A loop that costs a fraction of a cent per turn costs real money at three in the morning with no turn limit.
- Per-run token and turn ceilings, enforced in code
- A daily or per-tenant spend cap that hard-stops
- Timeouts on every external call, and on the run as a whole
- Alerting on a step change in spend, not just on a threshold
Done when: a runaway loop stops on its own and someone is told.
6. Make it auditable and reversible
- Log every action with its trigger: which request, which user, which turn led to it. When something goes wrong this is the only thing that lets you scope the damage.
- Tag agent-originated changes so they can be found and reverted as a set.
- Write the kill switch: a way to stop the agent that does not require a deploy. Test that it works, before you need it.
- Write the rollback for the actions it takes, where one is possible.
Done when: you could answer "what did the agent do between 2pm and 3pm, and can we undo it?"
7. Write the risk record
# <Agent> — risks and controls
| Risk | Worst case | Control | Enforced in | Tested by |
The "enforced in" column is the point of the whole document. If it says "system prompt", that is a soft control, and it belongs in a separate section clearly labelled as guidance rather than sitting alongside real limits. Mixing them produces a document that looks like safety and is not.
End with what you accepted: the risks you decided to live with, and why. An honest accepted-risk list is worth more than a document implying everything is covered.
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis. | Stars: 471k | Updated | Claude CodeCodex | Verified | Install |
| diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness. | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |