defending-against-prompt-injection

defending-against-prompt-injection is a skill for Claude Code from Hoja-Solutions/agent-stdlib. It costs 189 tokens per session (1,036 once invoked), scanned A, original, MIT.

A set of practices for preventing an agent from obeying hidden instructions inside webpages, emails, API responses, or other outside text. This attack, called prompt injection, tries to redirect the agent through content it is reading.

In plain words
What is it for?
Use it when an agent reads web pages, messages, documents, or API results. It helps label the source of content, keep it in tool results, screen it for suspicious instructions, and preserve the correct instruction hierarchy.
Why use it?
It separates trusted instructions from untrusted information so fetched content is treated as data, not as commands. That reduces the chance that an outside author can make the agent take unintended actions.

Skill for Claude Code

Written for Claude Code: PostToolUse hook event.

Part of the agent-stdlib plugin — 14 skills, 2 commands, 1 agent, 2 hooks, 2 MCP servers shipped together

Good fit Use it when an agent reads web pages, messages, documents, or API results. It helps label the source of content, keep it in tool results, screen it for suspicious instructions, and preserve the correct instruction hierarchy.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/hoja-solutions/agent-stdlib/defending-against-prompt-injection
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add Hoja-Solutions/agent-stdlib --skill defending-against-prompt-injection
Clone the repo
git clone --depth 1 https://github.com/Hoja-Solutions/agent-stdlib

Made for: Claude Code.

Or install agent-stdlib, the plugin that ships this one along with the rest of its 14 skills, 2 commands, 1 agent, 2 hooks, 2 MCP servers.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for defending-against-prompt-injection

README.md
[![agentmods](https://agentmods.dev/badge/skills/hoja-solutions/agent-stdlib/defending-against-prompt-injection/github.svg)](https://agentmods.dev/skills/hoja-solutions/agent-stdlib/defending-against-prompt-injection)
Your own site
<a href="https://agentmods.dev/skills/hoja-solutions/agent-stdlib/defending-against-prompt-injection"><img src="https://agentmods.dev/badge/skills/hoja-solutions/agent-stdlib/defending-against-prompt-injection/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for defending-against-prompt-injection

Your own site · 80×15
<a href="https://agentmods.dev/skills/hoja-solutions/agent-stdlib/defending-against-prompt-injection"><img src="https://agentmods.dev/badge/skills/hoja-solutions/agent-stdlib/defending-against-prompt-injection.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 189 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,036 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00189 $0.01036
Opus 5 $0.00095 $0.00518
Sonnet 5 $0.00038 $0.00207
Haiku 4.5 $0.00019 $0.00104

Measured 10d ago against content hash 20b0832ea218, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-10, from the pricing page.

Security

Grade A, and why

defending-against-prompt-injection scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 10d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/defending-against-prompt-injection/SKILL.md · 61 lines

How it starts

The opening of the file, as written. The whole thing — 61 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Defending against prompt injection

Source: Mitigate jailbreaks and prompt injection and Building trustworthy agents. The sandboxing skill caps what an attack can reach; this skill keeps the model from obeying the attack in the first place. The two stack: one deterministic boundary around the agent, one discipline for how third-party text enters its context.

An agent that reads outside text inherits a new attacker: whoever wrote the page, the email, or the API response it fetches. That text can carry instructions aimed at the model, and a helpful model follows them unless you arrange the context so it can tell your instructions from the data. The steps below lower the odds it confuses the two.

Keep untrusted content in tool_result blocks

Put every piece of third-party text in a tool_result block. Instruction-tuned models weight instructions inside a tool result below those in the system prompt, so a sentence that would hijack the agent from the system prompt carries far less weight there. The converse holds too: do not put your own instructions in a tool result, because the model discounts those as well. Send your instructions in a user turn after the result lands.

Wrap the content as data

Encode untrusted strings as JSON with explicit fields, such as {"source": "inbound_email", "from": "...", "body": "..."}. The escaping gives a hard boundary the attacker cannot step across: a line that tries to open a new instruction stays a string value inside body. Raw concatenated text has no such edge, so a crafted line reads as a fresh command.

Label where each block came from

Tell the model what a block is and who produced it. "The following is the body of an email from an unverified sender" sets how much trust to extend. An unlabeled block reads as authoritative by default.

Screen tool output before the agent acts

Read the full file on GitHub · 61 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 10d ago First seen · 61 lines · 189 tokens per session scan A 20b0832ea218

Subscribe to this mod's changes

defending-against-prompt-injection is a skill published in the GitHub repository Hoja-Solutions/agent-stdlib (1 stars, last pushed 1mo ago), licensed MIT. It adds 189 tokens to every session and 1,036 once invoked, about $0.0009 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

nft-standards

Implement NFT standards (ERC-721, ERC-1155) with proper metadata handling, minting strategies, and marketplace integration. Use when creating NFT contracts, building NFT marketplaces, or implementing digital asset systems.

wshobson/agents · 48 tokens

postgresql-table-design

Use this skill when designing or reviewing a PostgreSQL-specific schema. Covers best-practices, data types, indexing, constraints, performance patterns, and advanced features.

wshobson/agents · 37 tokens

istio-traffic-management

Configure Istio traffic management including routing, load balancing, circuit breakers, and canary deployments. Use when implementing service mesh traffic policies, progressive delivery, or resilience patterns.

wshobson/agents · 40 tokens

event-store-design

Design and implement event stores for event-sourced systems. Use when building event sourcing infrastructure, choosing event store technologies, or implementing event persistence patterns.

wshobson/agents · 33 tokens

projection-patterns

Build read models and projections from event streams. Use when implementing CQRS read sides, building materialized views, or optimizing query performance in event-sourced systems.

wshobson/agents · 36 tokens

workflow-orchestration-patterns

Design durable workflows with Temporal for distributed systems. Covers workflow vs activity separation, saga patterns, state management, and determinism constraints. Use when building long-running processes, distributed transactions, or microservice orchestration.

wshobson/agents · 49 tokens