security-guard

A generator for safety checks that stop an coding agent from running selected dangerous shell commands. It updates a project script and connects it to the agent's before-tool-use hook.

In plain words
What is it for?
Use it to add or update blocked command patterns, limit writes to selected folders, and prevent specific package-manager actions. It validates custom regular expressions and makes the security script executable.
Why use it?
It reduces the risk of accidental deletion, unsafe permissions, disk damage, protected-branch pushes, or remote code execution. It also lets you preview which existing commands would be blocked before enabling the rules.

Skill for Claude CodeCodex

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.

agentmods
npx agentmods add skills/sliday/harn/security-guard
Any agent
npx skills add sliday/harn --skill security-guard
Clone the repo
git clone --depth 1 https://github.com/sliday/harn

Made for: Claude Code, Codex.

Per session 36 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 798 The whole file, excluding the scripts and references it only reads on demand.
Security scan C 4 findings. Scan, not verified.
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 $0.00036 $0.00798
Opus 5 $0.00018 $0.00399
Sonnet 5 $0.00007 $0.00160
Haiku 4.5 $0.00004 $0.00080

Measured 2d ago against content hash 972d362904fb, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade C, and why

security-guard scanned grade C with 4 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 2d 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.

Asks for rootlowPrivilege escalation

A mod that escalates privileges can change anything on the machine, not only the project.

- `sudo rm` — privileged deletion

Downgraded: this mod is about security review, or the phrase is quoted, so it is likely naming the pattern rather than instructing it.

Downloads and executes remote codemediumSupply chain

curl | sh runs whatever the server returns today, which is not necessarily what it returned when this was reviewed.

- `curl | bash` — piped remote execution

Downgraded: this mod is about security review, or the phrase is quoted, so it is likely naming the pattern rather than instructing it.

Recursive force deletemediumDestructive command

rm -rf with a variable or a broad path is one typo away from removing the wrong tree.

- `rm -rf` — recursive forced deletion

Downgraded: this mod is about security review, or the phrase is quoted, so it is likely naming the pattern rather than instructing it.

Makes network callslowCapability

Not a fault in itself. Listed so you know the mod talks to something, and to what.

- `curl | bash` — piped remote execution
skills/security-guard/SKILL.md · 95 lines

How it starts

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

Security Guard Generator

Generate or update scripts/harness/security_guard.py for the current project.

Process

  1. Read current scripts/harness/security_guard.py if it exists
  2. Ask user what additional patterns to block (or accept defaults)
  3. Before adding user patterns, verify they compile as valid regex
  4. Offer to show the user what existing commands would be blocked by the new patterns before activating (--dry-run)
  5. Generate the updated script with all patterns
  6. Ensure it's executable
  7. Verify it's wired in .claude/settings.json as a PreToolUse hook

Default Blocked Patterns

  • rm -rf — recursive forced deletion
  • git push ... main/master — direct push to protected branches
  • chmod 777 — reckless permissions
  • > ~/ — overwriting home directory files
  • curl | bash — piped remote execution
  • sudo rm — privileged deletion
  • mkfs. — disk formatting
  • dd if= — raw disk writes

Custom Patterns

Ask the user if they want to:

  • Restrict writes to specific directories only (e.g., only src/)
  • Block specific package managers (e.g., npm publish)

Pattern Validation

Before adding user-supplied patterns, verify they compile as valid regex. Invalid patterns can silently break the guard or cause it to crash. Test each pattern with re.compile() and report errors back to the user before writing the script.

Dry Run

Offer to show the user what existing commands (from shell history or a sample list) would be blocked by the new patterns before activating. This helps catch overly broad patterns that would block legitimate work.

User-Supplied Patterns

User-supplied regex patterns may contain errors — unbalanced groups, invalid escapes, or overly broad expressions. The generated script wraps each re.search() call in a try/except for re.error so that a single bad pattern does not disable the entire guard.

Template

Generate scripts/harness/security_guard.py using this structure:

#!/usr/bin/env python3
# Harn security guard — blocks dangerous shell commands before execution
# Why: https://harn.app/kb/safety.html — "Tools should be hard to misuse"
# Docs: https://harn.app/kb/safety.html — "Mitigating Prompt Injection Attacks"

import json, sys, re

payload = json.load(sys.stdin)

if not isinstance(payload, dict):
    sys.exit(0)  # Malformed payload — allow (fail-open for non-Bash)

tool = payload.get("tool_name", "")
if tool != "Bash":
    sys.exit(0)

command = payload.get("tool_input", {}).get("command", "")

dangerous = [
    r"rm\s+-rf",
    r"git\s+push\s+.*\b(main|master)\b",
    r"chmod\s+777",
    r">\s*~/",
    r"curl\s+.*\|\s*bash",
    r"sudo\s+rm",
    r"mkfs\.",
    r"dd\s+if=",
]

for pattern in dangerous:
    try:
        if re.search(pattern, command):
            print(f"HARNESS BLOCK: Command matches prohibited pattern ({pattern}).", file=sys.stderr)
            print("Find a safer alternative.", file=sys.stderr)
            sys.exit(2)
    except re.error:
        print(f"HARNESS WARNING: Invalid regex pattern skipped: {pattern}", file=sys.stderr)
        continue

sys.exit(0)

Read the full file on GitHub · 95 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. 2d ago First seen · 95 lines · 36 tokens per session scan C 972d362904fb

Subscribe to this mod's changes

security-guard is a skill published in the GitHub repository sliday/harn (5 stars, last pushed 4mo ago), licensed MIT. It adds 36 tokens to every session and 798 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it C with 4 findings (asks for root, downloads and executes remote code, recursive force delete). 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

systematic-debugging

Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes.

obra/superpowers · 21 tokens

brainstorming

You MUST use this before any creative work - creating features, building components, adding functionality, or modifying behavior. Explores user intent, requirements and design before implementation.

obra/superpowers · 37 tokens

auto-perf-optimize

Run agent-driven VS Code performance or memory investigations. Use when asked to launch Code OSS, automate a VS Code scenario, run the Chat memory smoke runner, capture renderer heap snapshots, take workflow screenshots, compare run summaries, or drive a repeatable scenario before heap-snapshot analysis.

microsoft/vscode · 62 tokens

chat-perf

Run chat perf benchmarks and memory leak checks against the local dev build or any published VS Code version. Use when investigating chat rendering regressions, validating perf-sensitive changes to chat UI, or checking for memory leaks in the chat response pipeline.

microsoft/vscode · 51 tokens

chat-pet-sprite-creation

Use when creating or changing VS Code chat pet sprite art, sprite sheets, state animations, eye treatments, Stable/Insiders variants, or pet transitions under src/vs/workbench/contrib/chat/browser/widget/media/chatPet.

microsoft/vscode · 53 tokens

cpu-profile-analysis

Analyze V8/Chrome CPU profiles (.cpuprofile) and DevTools trace files (Trace-.json). Use when: profiling performance, investigating slow functions, comparing code paths, finding bottlenecks, analyzing timeToRequest, understanding call trees from sampling profiler data, analyzing layout/paint/rendering, investigating…

microsoft/vscode · 71 tokens