All guides

    Guide

    Why don't command denylists stop risky coding agent actions?

    Updated

    Short answer

    A denylist matches the text of a command, and the same action can be written many ways: a full path, a shell inside a shell, a different flag, an encoding, or a Python script. Anthropic's own Claude Code docs say a deny rule "isn't a security boundary around the program." Keep deny rules as a first filter, then add a sandbox, scoped credentials, controlled egress, and a check on what the action actually does.

    What a denylist actually does#

    A denylist compares the text of a command to a pattern. If the text matches, the command is stopped. If it doesn't, something else decides.

    That works when the agent writes the command the way you expected. It breaks when the same action shows up in a different form, and agents produce a lot of forms. It's one reason Harden's threat model is organized by harm to the business instead of by command strings.

    Anthropic's docs say it plainly#

    Claude Code's permission docs are honest about this. A rule "doesn't match the same program invoked in a different form, so a deny or ask rule covers the invocation Claude usually produces and isn't a security boundary around the program." (Claude Code permissions)

    Here's what "a different form" looks like for a few common prefix rules:

    Deny ruleMatchesSame action, different form
    Bash(curl *)curl https://example.com/usr/bin/curl ..., sh -c 'curl ...'
    Bash(rm *)rm -rf build//bin/rm -rf build/, bash -c 'rm -rf build/'
    Bash(git push *)git push origin maingit -C . push origin main

    Six ways text matching misses#

    • Quoting and nesting. sh -c '...' hides the real command inside a string.
    • Paths and aliases. /bin/rm isn't rm. A variable or alias can stand in for either.
    • Harmless-looking flags. find . -delete starts like a read-only command and ends as a delete.
    • Encodings. A base64 blob decoded and piped to a shell contains no pattern to match.
    • Symlinks and expansion. A path that looks local resolves somewhere else. A trailing ~/ in rm -rf tests/ patches/ plan/ ~/ expanded to a developer's whole home directory, as Simon Willison reported.
    • Another language. Deleting files or sending a secret from Python or Node never touches the rm or curl rule.

    Add length to the list. Adversa AI reported a deny-rule bypass in Claude Code where a command chain split into 51 subcommands got a generic prompt, "too many to safety-check individually," instead of a check on each one (Adversa's write-up). Whatever the patch status of that bug, parsers have limits, and a long enough string finds them.

    Where deny rules still earn their place#

    Don't delete them. A deny rule is cheap, readable, and catches the common, well-intentioned mistake: the agent typing git push --force the obvious way.

    Treat it as a first filter for a cooperative agent. It's weak against a prompt-injected one, or a model that reaches for a different path to the same goal.

    What works instead#

    Pick controls that don't depend on how the command is spelled.

    • A sandbox. Anthropic says effective sandboxing requires both filesystem and network isolation, and that in internal use it "safely reduces permission prompts by 84%" (Anthropic engineering). A sandbox bounds reach no matter what text ran. See sandboxing Claude Code and Codex.
    • Short-lived, scoped credentials. If the token can't delete production, no phrasing of the command will.
    • Controlled egress. Allow the hosts the task needs and nothing else.
    • A check on the action itself. Judge what the command does, not how it's spelled.

    For how these layers stack in Claude Code, see permissions vs hooks vs sandbox.

    Where Harden fits#

    Harden Agentic Integrity Foundation (AIF) runs on the developer laptop, outside the agent, at the agent's pre-execution hook. Every command, file edit and push is checked against the session's intent before it runs.

    Deterministic rules cover 10 kinds of risky action, the ones where the action itself is the evidence, like a secret reaching a network call or a recursive delete at the root. A local model reviews the action in context across 19 risk categories, and it can only make a verdict stricter, never weaker.

    Decisions are made locally, in about 28 ms (P99 about 70 ms). One policy covers every agent, and it starts watch-only, so you see what agents do before you enforce anything.

    It's a layer, not a perimeter. A determined attacker who controls the code can defeat static analysis, exfiltration spread across several separate calls is the hard case, and it doesn't replace least privilege, scoped credentials or egress policy. More at Harden for security teams.

    A decision rule#

    • Keep deny rules for the obvious mistakes.
    • Put anything irreversible behind a sandbox, scoped credentials and egress limits first.
    • Judge actions by what they do and where the result goes, not by their spelling.

    A denylist lists the commands you thought of. The agent only needs one you didn't.

    FAQ

    Related questions

    Are deny rules useless for coding agents?

    No. They catch the obvious, well-intentioned mistake cheaply. They just aren't a boundary against a different spelling of the same action, and Anthropic's docs say so.

    Is an allowlist safer than a denylist?

    An allowlist fails closed, so unknown commands don't run, which beats guessing what to block. But allow rules still match text, so an allowed wrapper or runner can carry whatever command follows it.

    Does a sandbox make a denylist unnecessary?

    A sandbox bounds what any command can reach, which matters more than the list. Anthropic notes it needs both filesystem and network isolation. It still doesn't judge whether an allowed action fits the task.

    Can a pre-execution hook replace pattern rules?

    A hook sees the pending action before it runs, so it can apply a real check instead of a prefix match. It's only as good as the check behind it.

    What does a check on the action catch that a pattern misses?

    It judges what the action does in the context of the session, so the same command can be fine in one task and blocked in another. Deterministic rules handle clear-cut cases, and a local model reviews the rest in context.

    Sources

    1. Configure permissions - Claude Code Docs
    2. Beyond permission prompts: making Claude Code more secure and autonomous (Anthropic Engineering)
    3. Claude Code security bypass: deny rules disabled (Adversa AI)
    4. Claude Code deleted a user's Mac (Simon Willison)

    Start free at harden.run

    Full Enterprise access, free for 60 days: unlimited developers, custom policies, centralized visibility, no commitment.