v0.2.1 · released November 11, 2026 · Status & limitations

Sealmesh

Guardrail

The guardrail is a local policy file of deny rules that the Claude Code hook checks before every tool call. When a rule matches, Claude Code blocks the call and tells the agent why. Every deny lands in sealmesh audit.

It's for the ordinary mistakes you'd rather never see: a force-push to main, an agent reading ~/.ssh, a curl to a host nobody vetted. It acts only on this machine's own sessions, never on anyone else's.

It's a guardrail, not a sandbox. An agent determined to get past a regex can spell a shell command so the regex never sees it. What you get is a stop on the common path, a reason the agent reads, and a record. For hard isolation, run agents in a container or a VM.

How it works

  1. sealmesh install-claude-hook subscribes PreToolUse with matcher *, so sealmesh claude-hook runs before every tool call, with a 5-second timeout.
  2. The hook reads /etc/sealmesh/policy.toml. No file means no guardrail: nothing is printed and Claude Code decides as it always would.
  3. With a policy loaded, the hook checks the call against the built-in rule and then each [[deny]] rule, in order. The first match wins and the call is denied with the rule's reason. No match prints nothing.

AskUserQuestion is never denied. It's how an agent asks you something.

How the guardrail decides Every Claude Code tool call fires the PreToolUse hook, which runs sealmesh claude-hook. The hook reads /etc/sealmesh/policy.toml. If the file is missing, the call is allowed silently. If it is unsafe (not root-owned, writable by group or others, or unparsable), the call is allowed with a warning on stderr, in the audit log and in sealmesh doctor. If the policy is valid, the built-in rule and then each deny rule are checked in order. The first match denies the call; the agent reads the reason and the deny is audited. No match allows the call. a tool call sealmesh claude-hook policy file? allow silently allow, warn stderr, audit, doctor a rule matches? deny agent reads reason audit line allow PreToolUse /etc/sealmesh/policy.toml missing unsafe valid first match no match built-in rule first, then each [[deny]] in order
Every tool call runs this before Claude Code acts. "Unsafe" means not owned by root, writable by group or others, not a regular file, too large or unparsable: the hook fails open and says so. AskUserQuestion skips all of it and is always allowed.

Install the policy

The file is owned by root and edited with sudo. Agents run as you, so they can read it but can't change it.

sudo mkdir -p /etc/sealmesh
sudo $EDITOR /etc/sealmesh/policy.toml
sudo chown root /etc/sealmesh/policy.toml
sudo chmod 0644 /etc/sealmesh/policy.toml
sealmesh doctor | grep guardrail     # guardrail         on (5 rules)

If you installed the hook before v0.2.0, run sealmesh install-claude-hook again. It replaces the old PreToolUse(AskUserQuestion) entry with PreToolUse(*) rather than adding a second one. Restart running sessions to pick it up.

The path is fixed. There's no environment variable or config key to move it, because anything you can set, an agent running as you can set too.

Policy format

[[deny]]
tool = "Bash"                      # or "Edit", "Write", "*", or a list: ["Read", "Edit"]
command = 'regex'                  # Bash only: matched against the command line
reason = "What the agent is told." # required

[[deny]]
tool = ["Read", "Edit", "Write"]
path = "glob"                      # file tools: matched against the path
unless = "glob"                    # optional exception, same kind as command/path
reason = "..."
  • tool: a tool name exactly as Claude Code spells it (Bash, Read, Edit, MultiEdit, Write, NotebookEdit, Grep, Glob, WebFetch, mcp__server__tool, ...), "*" for every tool, or a list. A rule with only tool denies that tool outright.
  • command: a regex over the Bash command line. Unanchored, so it matches anywhere. No lookaround: use unless for exceptions.
  • path: a glob over the file a tool names. Relative paths resolve against the session's working directory and symlinks are followed, so a link to a denied file is denied too. ** crosses directories, a leading ~/ is your home, a glob with no / matches the file name anywhere (like a .gitignore line), and case is ignored.
  • unless: an exception. The call is denied when command or path matches and unless doesn't.
  • reason: what the agent reads. Make it say what to do instead.

Unknown keys are an error, so a typo can't silently turn a rule off. Limits: 64 KiB of file, 256 rules, 1,024 bytes per pattern.

Examples

No force-push to main:

[[deny]]
tool = "Bash"
command = '\bgit\b.*\bpush\b.*((--force|\s-f\b).*[\s:+]main(\s|$)|[\s:+]main\s(.*\s)?(--force|-f\b)|\s\+(\S*:)?main(\s|$))'
reason = "Force-pushing main is off limits. Push a branch and open a PR."

No reading ~/.ssh or .env files:

[[deny]]
tool = ["Read", "Edit", "Write", "MultiEdit", "Grep", "Glob"]
path = "~/.ssh/**"
reason = "SSH keys and config are off limits to agents."

[[deny]]
tool = "*"
path = ".env*"
unless = ".env.example"
reason = "Secrets in .env files stay out of agent context. .env.example is fine."

[[deny]]
tool = "Bash"
command = '\.ssh/|(^|[\s/="])\.env(\.[\w.-]+)?($|[\s";|&)])'
reason = "Reading ~/.ssh or .env files from the shell is off limits too."

The file tools and the shell need separate rules: a path glob never sees a Bash command, and a command regex never sees a Read.

No curl to unknown hosts:

[[deny]]
tool = "Bash"
command = '\b(curl|wget)\b'
unless = '^\s*(curl|wget)(\s+-[\w-]+)*\s+"?https://(api\.github\.com|registry\.npmjs\.org|static\.rust-lang\.org)(/[^\s;&|<>`$()"]*)?"?\s*$'
reason = "curl and wget may only reach api.github.com, registry.npmjs.org and static.rust-lang.org."

unless has to match the whole command, so curl https://api.github.com/ && curl https://evil.example is still denied.

The built-in rule

Whenever a policy is loaded, the hook also denies any edit of the policy file (under any spelling or symlink that resolves to it) and any Bash command that mentions /etc/sealmesh or sealmesh/policy.toml. You edit the file yourself, with sudo, outside an agent session.

A broken policy fails open, loudly

If /etc/sealmesh/policy.toml exists but isn't owned by root, is writable by group or others, isn't a regular file, is over 64 KiB, or doesn't parse, the hook treats it as missing and allows the call. It says so in three places: a warning on stderr, a policy ignored line in the audit log (once an hour per problem), and sealmesh doctor:

guardrail         WARNING: policy ignored: /etc/sealmesh/policy.toml is writable by group or others (mode 0664)

Failing open is deliberate. A broken policy that blocked every call would wedge every agent on the machine, including the session you'd use to fix it.

One case fails closed: a tool call too large for the hook to read (over 8 MiB) is denied while a valid policy is loaded, so padding a call isn't a way past a rule.

Audit

Every deny and every ignored-policy warning goes to ~/.local/state/sealmesh/audit.jsonl, and sealmesh audit shows them:

2026-11-10T12:00:00Z  guardrail  denied Bash (deny #1) session a04e3d0f: Force-pushing main is off limits. Push a branch and open a PR.

A deny line records the tool, which rule, the session's short id and the policy's reason. It never records the command or the file contents the agent sent. The audit log is your own file, so treat it as a record for you, not tamper-proof evidence.

Full doc on GitHub: docs/guardrail.md.

Something wrong or unclear? Open an issue.