A seatbelt for AI coding agents: understands the shell commands they run and blocks or asks before the dangerous ones.
pip install seatbelt-guard Copy PIP instructions
Your AI agent can terraform destroy production, cat ~/.aws/credentials | curl ..., or git push --force origin main. seatbelt reads the command first and stops it.
It works out what a command really does (pipes, bash -c, $(...), base64 tricks, the script the agent just wrote), knows when it is pointed at production, shows what a deletion would actually touch before asking, and keeps a log of everything the agent ran. Zero dependencies, no network, about 60 ms per command.
Status: v0.1. Tested with unit tests, a ~270-command corpus and real Claude Code sessions. Claude Code on Linux is the only agent/OS combination exercised so far.
pipx run --spec seatbelt-guard seatbelt demo Use it with Claude Code in 60 seconds pipx install seatbelt-guard # a tool install keeps the hook's path stable (pip install works for a try-out) seatbelt install claude-code --write # shows what would change first if you leave out --write seatbelt doctor # proves it works: runs the installed hook against a force-push seatbelt doctor exists because the worst failure of a guardrail is a silent one: Claude Code lets commands through when a hook cannot run (binary moved, venv deleted). The doctor checks the settings and runs the installed hook for real.
Use them too. They answer different questions.
seatbelt catches the mistakes and the prompt-injected commands before they reach the sandbox, explains them, and logs them.
Every feature was tried against real Claude Code sessions, and the sessions found bugs the unit tests did not:
The notes on how the hook contract really behaves (a broken hook fails open, allow skips your prompts, which events fire when) are in docs/claude-code-hooks.md.
Does it send my commands anywhere? No. There is no network code at all and no telemetry. The audit log stays on your machine (mode 0600) with secrets redacted before anything is written.
How much does it slow things down? About 60 ms median per command on the machine it was built on (a bare python3 start is 11 ms). Invisible next to a model call.
Will it nag me? It is quiet by default: more than 150 everyday commands (npm test, kubectl get, terraform plan, rm -rf node_modules...) must stay silent in the tests, and seatbelt learn suggests allow rules from what you approve. You can see for yourself in ten seconds by pointing it at your own shell history (nothing is executed, previews are off, and the output is redacted so it is safe to paste into an issue):
seatbelt check --stdin --quiet < ~/.bash_history # zsh history works too: < ~/.zsh_history What if it breaks? It fails closed (an internal error becomes an ask), the installer adds onFailure: block where Claude Code supports it, and seatbelt doctor verifies the hook is installed and live.
Can a repo I clone switch it off? No. A project's seatbelt.toml can only add restrictions; only your user config can allow things.
Which agents? Claude Code today. The adapter is about 130 lines (hook.py); issues for others welcome.
Is it a sandbox? No, see "What it cannot do" below.
Is this the same as agentseatbelt on PyPI? No, that is a different project (budget caps, rate limits and loop detection for agents). This one checks the shell commands an agent is about to run. The PyPI package here is seatbelt-guard; the command is seatbelt.
People now let agents run aws, kubectl, terraform, git and SQL on their machines. The fear is reasonable:
git clone https://github.com/nikhilrai-tech/seatbelt-for-AI-agents && cd seatbelt-for-AI-agents python3 -m venv .venv && .venv/bin/pip install -e . .venv/bin/seatbelt check 'rm -rf ~' # DENY: irreversible .venv/bin/seatbelt check 'cd /tmp && bash -c "git push --force origin main"' .venv/bin/seatbelt check --file examples/commands.txt # ~100 commands with expected verdicts check never runs anything; it only explains. Exit code is 0 allow, 1 ask, 2 deny.
DENY cd /tmp && bash -c "git push --force origin main" - force-push rewrites remote history of a protected branch (main) [git.push.force] Use it with Claude Code .venv/bin/seatbelt install claude-code # shows what would change, writes nothing .venv/bin/seatbelt install claude-code --scope project --write # ./.claude/settings.json (or --scope user) .venv/bin/seatbelt log # everything the agent ran, with the decision From then on, every Bash/PowerShell call goes through seatbelt first. Safe commands are silent; risky ones show the usual permission prompt with the reason; dangerous ones are blocked and the agent is told why. Existing settings are merged (a .bak is kept), and seatbelt uninstall claude-code --write removes only seatbelt's entry.
For unattended agents (claude -p, CI) use seatbelt install claude-code --headless --write, so every would-be prompt becomes a block instead of a dead end.
Verified end to end on Claude Code 2.1.302: a force-push to main was blocked and the agent reported the reason without trying a workaround. The audit log (~/.local/state/seatbelt/audit.jsonl, mode 0600) records each command with secrets redacted. How the hook contract works, and why a broken hook is the real risk, is in docs/claude-code-hooks.md.
Secrets and prompt injection (the other half of what people are afraid of):
The file tools are covered too: Read on a secret file asks, Write/Edit on the agent's own settings is denied.
Covered so far: rm, find -delete, dd, mkfs/fdisk and friends, chmod/chown -R, shred, redirects into disk devices, fork bombs, git (force-push, reset --hard, clean -f, branch/stash/reflog destruction, history rewrites), sudo, kill, systemctl, crontab -r, firewalls, power commands.
A prompt that says "recursive delete of src" doesn't help anyone decide. So before asking, seatbelt measures the target:
ASK rm -rf src - recursive delete of /home/me/app/src [fs.rm.recursive] = impact: deletes 27 files in 2 folders (1.4 MB) under /home/me/app/src; 27 files changed in the last 24 hours, so possibly uncommitted work; includes .env, local.sqlite, which are probably not in version control File and folder counts, size, whether a .git directory is inside, how much changed in the last 24 hours (a stand-in for uncommitted work), and files that usually are not in version control (.env, keys, local databases, state files). In a real Claude Code session the agent read this and offered to back the folder up first.
Deleting a dev namespace and deleting prod are different acts, so seatbelt works out where a command runs: --profile prod, --context prod-eu, -n production, -var-file=prod.tfvars, a host or database called prod-db, AWS_PROFILE, TF_WORKSPACE, RAILS_ENV, DATABASE_URL, kubeconfig's current-context, terraform's .terraform/environment file, an infra/prod/ directory. Whole words only (products-bucket is not production).
Covered: aws (incl. s3, IAM changes, secret reads, expensive instances, open security groups), gcloud/gsutil, az, heroku/flyctl/vercel/doctl/firebase..., gh, kubectl/oc/helm, terraform/tofu/pulumi/cdk/serverless, SQL in psql/mysql/sqlite3 (inline, -f file, here-docs, pipes; comments and string literals don't fool it), Redis, Mongo, migration tools (rails, prisma, django, alembic, ...), docker/compose, and publishing (npm publish, twine upload, cargo publish, docker push). Dry runs (--dry-run, --dryrun) are recognised and left alone.
~/.config/seatbelt/config.toml, or $XDG_CONFIG_HOME/seatbelt/config.toml if you set it (see examples/config.toml):
trusted_hosts = ["api.github.com", "*.mycompany.com"] # secret variables may go to these without asking prod_patterns = ["live"] # extra words that mean production [[allow]] command = "git push origin feature/*" [[deny]] command = "kubectl * --context=prod*" reason = "no agent touches the prod cluster" allow only lowers an ASK. It can never lower a DENY, or an ask about tampering with the guardrails, and it is matched literally (otherwise an allow for git push origin feature/* would also wave through git push -f origin feature/x). deny/ask also match with the flags removed, so npm run --silent deploy is caught by npm run deploy*. A flag that takes a value leaves the value behind: write npm * run deploy* to cover npm --prefix app run deploy. A project can restrict but never permit. A seatbelt.toml in the repository may add deny, ask and prod_patterns; its allow and trusted_hosts are ignored (and reported). Otherwise a cloned repo could grant its own agent permissions. A broken config file is an ASK, never silently ignored. seatbelt check --config FILE tries a config; --no-config ignores all. Learn mode: fewer prompts without loosening anything blindly Prompts you always approve are noise, and noise trains people to click through. The hook logs each decision and, when Claude Code reports that the call ran, a second row with the same tool_use_id (verified on 2.1.302: a command that ran fires PostToolUse, one that exited non-zero fires PostToolUseFailure, one a hook denied fires neither). An ASK followed by that row was approved by you.
seatbelt learn # reads the audit log, prints suggestions, changes nothing Looked at 41 prompts: 33 approved, 5 declined or never ran, 3 still pending. Approved at least 3 times, safe to suggest: 1. git push --force origin feature/* approved 6x, e.g. `git push --force origin feature/login` [[allow]] command = "git push --force origin feature/*" reason = "approved 6 times" Not suggested: - kubectl delete pod web-1 (approved 4x, but it was also declined or never ran 1 time(s)) - cat ~/.aws/credentials (never suggested for secret) You paste what you agree with into your user config. Rules of the road:
seatbelt is a guardrail, not a sandbox. It reads commands and scripts before they run and refuses the ones it understands to be dangerous. It cannot give a hard guarantee:
For a hard guarantee, run the agent in a container or VM with only the access it needs, and use seatbelt on top of it: it catches the mistakes and the prompt-injected commands before they get that far, explains them, and keeps a log.
Apache-2.0, see LICENSE. Commits made before this change were published under the MIT license; copies obtained under MIT may continue to be used under MIT.
If seatbelt saved you a bad day, a star helps others find it. If it gets a command wrong, in either direction, please open an issue with the template and seatbelt check --json ' '; those reports are the most useful thing you can send. See CONTRIBUTING.md and SECURITY.md.
ai-agents security guardrails devops claude-code shell
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 19, 2026.




