agent-hardening
Skill4 starsChanged 4 months agoMITView on GitHub
Makes 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.
In this repository61 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- agent-deploymentSkill
- agent-designSkill
- agent-evaluationSkill
- agent-implementationSkill
- agent-observabilitySkill
- agent-scopingSkill
- api-designSkill
- code-templatingSkill
- dependency-upgradeSkill
- error-handlingSkill
- feature-implementationSkill
- project-scaffoldingSkill
- refactoringSkill
- data-analysisSkill
- data-migrationSkill
- data-modelingSkill
- sql-queriesSkill
- ci-pipelinesSkill
- containerizationSkill
- deployment-strategiesSkill
- infrastructure-as-codeSkill
- debuggingSkill
- issue-investigationSkill
- issue-triageSkill
- log-analysisSkill
- network-troubleshootingSkill
- performance-profilingSkill
- api-documentationSkill
- commit-messagesSkill
- diagrammingSkill
- markdown-docsSkill
- plain-languageSkill
- pr-descriptionsSkill
- release-notesSkill
- browser-testingSkill
- integration-testingSkill
- load-testingSkill
- test-dataSkill
- test-driven-developmentSkill
- unit-testingSkill
- deep-researchSkill
- feed-digestSkill
- summarizationSkill
- accessibility-reviewSkill
- code-analysisSkill
- code-lintingSkill
- code-reviewSkill
- auth-designSkill
- dependency-auditSkill
- secrets-managementSkill
- security-analysisSkill
- threat-modelingSkill
- capacity-planningSkill
- disaster-recoverySkill
- incident-responseSkill
- monitoring-setupSkill
- root-cause-analysisSkill
- runbooksSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 4 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 39
Filter the tool surface at construction: If the job list needs 20 operations out of a 500-operation API, expose 20.
- Distinctive: line 42
Never a shared admin credential: When something goes wrong you need to know it was the agent, and you need to revoke it alone.
- Distinctive: line 64
Test it: Put injection attempts in the eval set as permanent cases.
- Distinctive: line 81
Done when: every irreversible action is gated, and the cap on repeated actions is enforced.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
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.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

