squidbrake 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,15 @@
1
+ # your keys, settings, history and local environment (never commit these)
2
+ MY_*
3
+ .env
4
+ .env.*
5
+ !.env.example
6
+ data/
7
+ .venv/
8
+ dist/
9
+ __pycache__/
10
+ .pytest_cache/
11
+ *.bak
12
+ *.bak-*
13
+
14
+ # the marketing site is a separate project
15
+ squidbreak-site/
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,381 @@
1
+ Metadata-Version: 2.5
2
+ Name: squidbrake
3
+ Version: 0.3.0
4
+ Summary: Brakes for AI agents: every tool call is checked against your rules, risky ones wait for a human, and everything lands in a tamper-evident audit trail.
5
+ Project-URL: Homepage, https://github.com/batrapulkit/squidbrake
6
+ Project-URL: Source, https://github.com/batrapulkit/squidbrake
7
+ Project-URL: Issues, https://github.com/batrapulkit/squidbrake/issues
8
+ Project-URL: Demo, https://codespaces.new/batrapulkit/squidbrake
9
+ Author: Pulkit Batra
10
+ License-Expression: Apache-2.0
11
+ License-File: LICENSE
12
+ Keywords: ai-agents,approval,audit,claude-code,guardrails,human-in-the-loop,mcp,security
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Environment :: Web Environment
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Topic :: Security
19
+ Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
20
+ Requires-Python: >=3.10
21
+ Requires-Dist: fastapi>=0.110
22
+ Requires-Dist: httpx>=0.27
23
+ Requires-Dist: mcp<3,>=2.2
24
+ Requires-Dist: python-dotenv>=1.0
25
+ Requires-Dist: pyyaml>=6.0
26
+ Requires-Dist: segno>=1.6
27
+ Requires-Dist: sqlalchemy>=2.0
28
+ Requires-Dist: uvicorn[standard]>=0.29
29
+ Provides-Extra: postgres
30
+ Requires-Dist: psycopg[binary]>=3.1; extra == 'postgres'
31
+ Description-Content-Type: text/markdown
32
+
33
+ # Squidbrake
34
+
35
+ [![tests](https://github.com/batrapulkit/squidbrake/actions/workflows/tests.yml/badge.svg)](https://github.com/batrapulkit/squidbrake/actions/workflows/tests.yml)
36
+ [![License: Apache 2.0](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](LICENSE)
37
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10%2B-blue.svg)](requirements.txt)
38
+ [![MCP](https://img.shields.io/badge/MCP-compatible-8A2BE2.svg)](#2-connect-real-agents)
39
+
40
+ ![Demo: an AI agent's scam wire is blocked, a refund waits for approval and is approved from a phone](https://raw.githubusercontent.com/batrapulkit/squidbrake/main/docs/demo.gif)
41
+
42
+ **Brakes for your AI agents.** Every action an agent takes (running a command, editing a file, sending an
43
+ email, issuing a refund, changing a database) goes through Squidbrake first. It is **checked** against your
44
+ rules, **held for a person** when it's risky, **recorded** in a tamper-evident audit trail, and can be
45
+ **stopped** instantly.
46
+
47
+ Free and open source (Apache 2.0). Runs on your laptop or your own server; your data never leaves it.
48
+
49
+ - **Rules, not vibes:** `rules.yaml` says what runs by itself, what's blocked, and what waits for a person.
50
+ No LLM in the decision path.
51
+ - **Human approval:** risky actions wait in the dashboard, on your phone (one-tap links, push via ntfy) or in Slack.
52
+ The approver sees *what led to it*, e.g. the email the agent just read.
53
+ - **Reads what a command really does:** `ls && rm -rf ~/`, `bash -c "..."`, `rmdir /s /q d:\` or `curl ... | sh` are
54
+ split and read before they run. Wiping a disk or home folder is blocked; `git push --force`, `terraform destroy`,
55
+ `kubectl delete` or cloud deletes wait for a person; commands that only look (`ls`, `git status`) run without asking.
56
+ - **Catches prompt injection without a model:** if an agent sends data to an address that only a web page, email or
57
+ issue mentioned (not you, not your own systems), it's held and the approver is told where the address came from.
58
+ - **Judges by history:** blocks a retry of something a person rejected, catches look-alike domains
59
+ (`acrne-corp.com` pretending to be `acme.com`), flags duplicate refunds, and lets you write sequence rules
60
+ ("deleting a database right after its backups were turned off") that say which earlier step caused them.
61
+ - **Works with real agents:** one command connects Claude Code (every tool call, via hooks), and any MCP app
62
+ (Stripe, GitHub, Slack, databases, internal tools) can be wrapped for Antigravity, Cursor, Claude Desktop and others.
63
+ - **For teams:** a key per person and per agent, roles (only `finance` approves wires), an emergency stop (all agents,
64
+ one agent, or one conversation, which also ends Claude Code's turn),
65
+ reports, CSV export, and evidence anyone can verify offline (`python verify.py`).
66
+ - **Fails closed:** if Squidbrake is down, guarded tools don't run.
67
+
68
+ See [SHOWCASE.md](SHOWCASE.md) for a 5-minute demo with a sandbox company, and [incidents/](incidents/) for **8 real
69
+ AI-agent incidents replayed against the shipped rules** (Replit, the Railway volume deletion, GitHub MCP, Supabase
70
+ MCP, Claude Code and Antigravity deletes...): 11 of 11 harmful actions stopped, checked in CI.
71
+
72
+ ![Squidbrake dashboard: a git push and a refund wait for approval, while a scam wire transfer was blocked](https://raw.githubusercontent.com/batrapulkit/squidbrake/main/docs/dashboard.png)
73
+
74
+ <table><tr>
75
+ <td width="62%"><img src="https://raw.githubusercontent.com/batrapulkit/squidbrake/main/docs/blocked-scam.png" alt="A $24,800 wire blocked because it follows an email from a look-alike domain"><br>
76
+ <sub>An agent read an "urgent CEO" email from <code>acrne-corp.com</code> and tried to wire $24,800. Blocked, with the story of what led to it.</sub></td>
77
+ <td width="38%"><img src="https://raw.githubusercontent.com/batrapulkit/squidbrake/main/docs/phone-approval.png" alt="One-tap approval on a phone"><br>
78
+ <sub>Approve or reject from your phone with one tap.</sub></td>
79
+ </tr></table>
80
+
81
+ ## See it live, nothing to install
82
+
83
+ [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/batrapulkit/squidbrake?quickstart=1)
84
+
85
+ Click the button and the live demo starts in your browser (free with a GitHub account): a sandbox company's AI
86
+ support agent works its inbox while you watch. A scam wire is blocked, refunds wait for a person, and a demo
87
+ manager approves or rejects them. If the editor asks whether to allow tasks that run automatically, click
88
+ **Allow**: that's the demo starting. On your own machine: `pip install -r requirements.txt` then `python demo/live_demo.py`.
89
+
90
+ ## Try it in 30 seconds
91
+
92
+ ```bash
93
+ pipx install squidbrake # or: pip install squidbrake
94
+ squidbrake # prints your keys and opens the dashboard
95
+ ```
96
+
97
+ Then connect Claude Code, so every tool call goes through Squidbrake from then on. Either as a plugin, from inside
98
+ Claude Code (it asks for the agent key the gateway printed; see [plugin/](plugin/)):
99
+
100
+ ```
101
+ /plugin marketplace add batrapulkit/squidbrake
102
+ /plugin install squidbrake@squidbrake
103
+ ```
104
+
105
+ or from the terminal: `squidbrake connect claude-code`. Your rules, keys and data live in `~/.squidbrake`;
106
+ edit `~/.squidbrake/rules.yaml` and changes apply at once.
107
+
108
+ From a clone instead: `git clone https://github.com/batrapulkit/squidbrake && cd squidbrake`, then `./start.sh`
109
+ (Windows: `start.bat`) and `./connect.sh claude-code` (Windows: `connect.bat claude-code`).
110
+
111
+ Or with Docker: `docker run -d -p 8080:8080 -v squidbrake-data:/app/data --name squidbrake ghcr.io/batrapulkit/squidbrake`
112
+ (keys: `docker logs squidbrake`).
113
+
114
+ ## 1. Start it
115
+
116
+ | Where | Command |
117
+ |---|---|
118
+ | Windows | double-click `start.bat` |
119
+ | macOS / Linux | `./start.sh` |
120
+ | A Linux server, 24/7 | `./install.sh` (or `./install.sh gateway.yourdomain.com` for HTTPS) |
121
+
122
+ The first start installs everything, prints an **admin** key (for the dashboard) and an **agent** key
123
+ (shown once, so save them), and opens `http://localhost:8080/dashboard`. No configuration needed; every
124
+ setting in `.env.example` is optional.
125
+
126
+ Keys: `python server.py add-key NAME [--approver]`, `python server.py remove-key NAME`, `python server.py keys`.
127
+ Changes apply immediately, no restart needed. (Inside Docker, prefix with `docker compose exec gateway`.)
128
+
129
+ ## 2. Connect real agents
130
+
131
+ With the gateway running, one command per agent (installed with pip, type `squidbrake connect ...` instead;
132
+ from a clone, use the `.venv` Python that `start.bat` / `start.sh` created):
133
+
134
+ ```bash
135
+ .venv/Scripts/python connect.py claude-code # Windows (macOS/Linux: .venv/bin/python)
136
+ .venv/Scripts/python connect.py mcp --name antigravity # also: claude-desktop, cursor
137
+ ```
138
+
139
+ - **Claude Code**: a hook sends *every* tool call (Bash, PowerShell, Edit, Write, Read, WebFetch, MCP tools)
140
+ through the gateway before it runs. Blocked calls are refused with the reason, and calls held for
141
+ approval wait until you decide in the dashboard. It also adds the database tools below.
142
+ Add `--project DIR` to limit it to one project; `--remove` undoes it. If the gateway is down, Claude Code's
143
+ tool calls are blocked (fail closed) and it says why.
144
+ - **Antigravity, Claude Desktop, Cursor, any MCP client**: prints the config block to paste in. The agent
145
+ gets `list_tables`, `describe_table`, `query` and `execute` tools on a SQLite database
146
+ (`data/shop.db`, created with sample customers / products / orders; set `DB_PATH` to use your own).
147
+ Reads run immediately, `UPDATE`/`DELETE`/`INSERT`/`ALTER` wait for your approval, and `DROP`/`TRUNCATE` are blocked.
148
+
149
+ Wrapping a GitHub or Stripe MCP server? Start with the commented example policies in
150
+ [`examples/rules/`](examples/rules/) and adjust their tool-name patterns to the server's tool list.
151
+
152
+ Things to ask the agent, then watch the dashboard:
153
+
154
+ - "Show me the top 5 customers by revenue" (runs)
155
+ - "Give every customer on the team plan a 15% discount" (waits for you to approve)
156
+ - "Delete all failed orders" (approve or reject it; a rejection note is passed back to the agent)
157
+ - "Drop the orders table" (blocked)
158
+ - In Claude Code: "commit and push this" (the `git push` waits for approval)
159
+
160
+ ## 3. Show it to someone
161
+
162
+ - **Right now, from your PC:** `cloudflared tunnel --url http://localhost:8080` prints a public
163
+ `https://….trycloudflare.com` link. Give viewers their own key: `python server.py add-key guest`.
164
+ Afterwards, press Ctrl+C and run `python server.py remove-key guest`.
165
+ - **Permanently:** `./install.sh gateway.yourdomain.com` on a small cloud server.
166
+
167
+ ## 4. Other computers (a friend, a teammate, a server)
168
+
169
+ Make a clean copy (no keys, no history): `python pack.py` -> `dist/squidbrake.zip`.
170
+
171
+ - **Their own gateway:** unzip, double-click `start.bat` (Windows) or run `./start.sh`. It makes its own keys.
172
+ - **Their agents on YOUR gateway:** in your dashboard's **Team** tab add them (a person, to watch/approve) and add
173
+ their agent (type *AI agent*); send them that agent key. They unzip and run, for example:
174
+ `connect.bat wrap --sandbox --agent claude-code --url https://your-gateway --key gw_...`
175
+ (or `connect.bat claude-code --url ... --key ...` to route every Claude Code action through your gateway).
176
+ - **A cloud server, 24/7:** unzip there and run `bash install.sh` (HTTPS included, no domain needed).
177
+
178
+ ## Other ways to send calls through it
179
+
180
+ **Python** - wrap your tools:
181
+
182
+ ```python
183
+ from client import Gateway, Denied
184
+ gw = Gateway("https://gateway.example.com", api_key="...", source="my-agent", session_id=run_id)
185
+
186
+ @gw.guard(name="shell.exec")
187
+ def shell_exec(command: str): ...
188
+ ```
189
+
190
+ **Any language** - two HTTP calls (header `X-Gateway-Key: <secret>`):
191
+
192
+ ```
193
+ POST /v1/events {"name": "shell.exec", "input": {...}, "source": "...", "session_id": "..."}
194
+ -> {"event_id": "...", "decision": "allow" | "deny", "reason": "...", "rule_id": ...}
195
+ POST /v1/events/{id}/result {"output": ..., "error": null, "duration_ms": 12}
196
+ ```
197
+
198
+ Record an action that already happened in one call by including `output`/`error` in the first POST.
199
+
200
+ **HTTP proxy** - no code changes: define `upstreams` in `rules.yaml`, then point the client at
201
+ `http://gateway:8080/proxy/<upstream>/...`. Optional headers: `X-Gateway-Source`, `X-Gateway-Session`.
202
+ Denied requests get `403`; every response carries `X-Gateway-Event-Id`.
203
+
204
+ ## Try it on real work first: shadow mode
205
+
206
+ Set `mode: shadow` in `rules.yaml` (or `shadow_agents: ["new-bot*"]` for some agents) and Squidbrake blocks and holds
207
+ nothing: it records what it *would* have done. Reports then shows **would block** and **would hold** counts, and each
208
+ event is tagged, so a team can see a week of real decisions before switching `mode: enforce` on. Stops and
209
+ catastrophic commands (`rm -rf /`, wiping a drive) are enforced even in shadow mode.
210
+
211
+ ## Command checks
212
+
213
+ Shell tools (Claude Code's `Bash` and `PowerShell`, or any tool matching `command_checks.tools`) are read by
214
+ [`commands.py`](commands.py) before the rules decide: the line is split on `&&`, `;`, `|` (outside quotes), and
215
+ `sudo`, `xargs`, `bash -c`, `powershell -Command` and `$(...)` are looked inside. Nothing is ever run or expanded.
216
+
217
+ | Kind | Examples | Default |
218
+ |---|---|---|
219
+ | catastrophic | `rm -rf /`, `rm -rf ~`, `rmdir /s /q d:\`, `mkfs`, `dd of=/dev/sda`, `chmod -R 777 /` | block |
220
+ | irreversible | `rm -r`, `git push --force`, `git reset --hard`, `terraform destroy`, `kubectl delete`, `aws ... delete-*`, `DROP TABLE` | review |
221
+ | hidden | `eval`, `curl ... \| sh`, `base64 -d \| bash`, `powershell -EncodedCommand` | review |
222
+ | read_only | `ls`, `cat`, `grep`, `git status` / `log` / `diff` | `allow` in the shipped `rules.yaml` |
223
+
224
+ Command checks apply even when a rule allows the tool, and `read_only: allow` only relaxes the `default` (never a
225
+ rule or a warning). Configure them under `command_checks:` in `rules.yaml`.
226
+
227
+ ## Prompt injection, caught without a model
228
+
229
+ The attacks that actually happened to agents (a GitHub issue, a support ticket or a web page telling the agent to send
230
+ data somewhere) share one shape: the destination comes from content someone else wrote. Squidbrake records what you
231
+ ask (Claude Code prompts, via the hook) and which tools bring in outside content (`WebFetch`, inboxes, issues,
232
+ tickets...). When an action sends something to an email address, URL, bank account or repo that appears in that
233
+ outside content but not in what you asked or in your own systems' results, it's held with the reason:
234
+
235
+ > This sends to keys@evil.io (to), which appears in WebFetch (2 minutes ago) but not in anything you asked or in your
236
+ > own systems. Content from outside can carry hidden instructions (prompt injection).
237
+
238
+ Uploads from the shell count too (`curl -d @.env https://...`, `scp`, `git push`). Anything sent out after outside
239
+ content was read gets a warning for the approver. Configure it under `taint_checks:` in `rules.yaml`.
240
+
241
+ ## Sequence rules
242
+
243
+ Some actions are only dangerous because of what came before them. `sequences:` in `rules.yaml` judges an action by
244
+ the steps before it and names the step that caused the decision:
245
+
246
+ ```yaml
247
+ sequences:
248
+ - id: destroy-after-recovery-removed # turn off backups, then delete the database
249
+ action: review
250
+ reason: Destroying data right after its backups or deletion protection were turned off
251
+ match: { input_regex: 'delete[-_ ]?db[-_ ]?instance|terraform\s+destroy|drop\s+(table|database)' }
252
+ after:
253
+ match: { input_regex: 'backup[-_ ]?retention[-_ ]?period\W{0,4}0|deletion[-_ ]?protection\W{0,4}false' }
254
+ within_hours: 24
255
+ - id: runaway-refunds # an agent stuck in a loop
256
+ action: deny
257
+ reason: Too many refunds in a short time
258
+ match: { name: ["*refund*"] }
259
+ count: { more_than: 10, within_hours: 1, scope: agent }
260
+ ```
261
+
262
+ The approver then sees, for example: *Destroying data right after its backups were turned off. Because earlier:
263
+ Bash `aws rds modify-db-instance --backup-retention-period 0` (12 minutes ago).* `after:` looks at steps in the same
264
+ conversation that went ahead (`same_target: true` = on the same charge, file or account); `count:` counts earlier
265
+ matching actions per `session`, `agent` or `all`. Actions: `deny`, `review` or `warn`.
266
+
267
+ ## Human approval
268
+
269
+ Rules with `action: review` hold the call until a person approves or rejects it:
270
+
271
+ ```yaml
272
+ - id: approve-payments
273
+ action: review
274
+ reason: Money movement needs a human
275
+ timeout_seconds: 600 # default APPROVAL_TIMEOUT (300)
276
+ on_timeout: deny # or allow
277
+ approvers: [alice, bob] # optional; default = any approver key
278
+ match: { name: "payments.*" }
279
+ ```
280
+
281
+ - The first `POST /v1/events` returns `"decision": "review"`. **The Python client handles this for
282
+ you**: `check()` and `@gw.guard` block until the call is decided, then run the tool or raise `Denied`.
283
+ Other clients long-poll `GET /v1/events/{id}/decision?wait=25` until `decision` is `allow` or `deny`.
284
+ - To decide, use the **Needs approval** queue at the top of the dashboard, or call
285
+ `POST /v1/events/{id}/approve` / `.../reject` with an optional `{"note": "..."}`.
286
+ - Only approver keys (`python server.py add-key NAME --approver`, and the rule's `approvers` if set) can decide,
287
+ and **a key can never approve its own request**. So give people their own keys, separate from the agents' keys.
288
+ - If nobody decides before the deadline, `on_timeout` applies and `decided_by` is recorded as `timeout`.
289
+ - Every decision is stored on the event with who decided, when, and their note.
290
+ - Set `APPROVAL_WEBHOOK_URL` (plus `PUBLIC_URL`) to get a Slack-style message with a link to the event
291
+ whenever something needs approval.
292
+ - Through the HTTP proxy, a held request stays open until it's decided, so the caller's HTTP
293
+ timeout must be longer than the rule's `timeout_seconds`.
294
+
295
+ ## Dashboard
296
+
297
+ Open `http://<host>:8080/dashboard` and paste your admin key (or any key made with `add-key`). It is stored
298
+ only in that browser. The page shows:
299
+
300
+ - totals per status (click a tile to filter), a calls-per-hour/day chart (hover for counts,
301
+ click a bar to list just that hour, "View as table" for exact numbers), and the top tools
302
+ - the event list, updated every 5 s while "Live" is on. Filter by time range, search, status,
303
+ kind, source or session. Click a source or session to filter by it. "Load older" pages back.
304
+ - the full record for any event: input, output, error, metadata, the rule that blocked it, timings
305
+ - filters are kept in the URL, so a view like `/dashboard?status=denied&range=7d` can be bookmarked or shared
306
+
307
+ ## FAQ
308
+
309
+ ### How is Squidbrake different from Claude Code's built-in allow/ask permissions?
310
+
311
+ Claude Code's built-in permissions control actions for an individual agent. Squidbrake provides **centralized rules for a whole team**, with approvals from your **phone or Slack**, history checks, an **audit trail**, and support across multiple agents.
312
+
313
+ ### What happens if Squidbrake is down?
314
+
315
+ Squidbrake **fails closed**. Guarded tool calls are blocked if the gateway is unreachable, rather than being allowed through.
316
+
317
+ ### Does my data leave my machine?
318
+
319
+ No. Squidbrake is **self-hosted** and runs on your laptop or your own server. Your data stays in your environment.
320
+
321
+ ### Does Squidbrake use an LLM to make decisions?
322
+
323
+ No. Squidbrake uses **deterministic rules and checks**. There is no LLM in the decision path.
324
+
325
+ ### Can an agent get around Squidbrake?
326
+
327
+ An agent cannot bypass Squidbrake through tools that are connected to the gateway. An agent could still use a tool that **isn't connected to Squidbrake**. See [`SECURITY.md`](SECURITY.md) for the security model and limitations.
328
+
329
+ ## Querying
330
+
331
+ | Endpoint | |
332
+ |---|---|
333
+ | `GET /v1/events?q=&session_id=&source=&client=&kind=&name=&status=&since=&before=&limit=` | newest first, page with `before=<next_before>` |
334
+ | `GET /v1/events/{id}` | one event |
335
+ | `GET /v1/events/{id}/decision?wait=25` | current decision; long-polls while awaiting approval |
336
+ | `POST /v1/events/{id}/approve` · `/reject` | human decision, body `{"note": "..."}` (approver keys only) |
337
+ | `GET /v1/me` | which key you are and whether it can approve |
338
+ | `GET /v1/stats?hours=24&bucket=hour` | counts by status, top tool names, timeline (same filters as events) |
339
+ | `POST /v1/policy/check` | dry-run a call against the rules (not recorded) |
340
+ | `GET /docs` | interactive OpenAPI docs |
341
+
342
+ ## Evidence anyone can check
343
+
344
+ Every decision is written to a hash-chained audit trail together with the fingerprint of the `rules.yaml` version
345
+ that made it, and each version's text is kept. **Reports > Tamper check > Download evidence** (or
346
+ `GET /v1/audit/export.json`) gives one file that anyone can check on their own machine, without trusting the server:
347
+
348
+ ```bash
349
+ python verify.py squidbrake-evidence-20261001-0930.json
350
+ ```
351
+
352
+ It confirms the chain is unbroken, that every recorded action still matches the fingerprint taken when it happened
353
+ (so rows edited in the database are caught, not just edits to the log), and that every decision's rules version is
354
+ in the file. `verify.py` needs only the Python standard library. The dashboard's tamper check runs the same checks live.
355
+
356
+ ## Behaviour notes
357
+
358
+ - **Fail closed**: the Python client refuses to run a tool if the gateway is unreachable
359
+ (`fail_open=True` to change that).
360
+ - **Rules hot-reload** on file save; a broken edit is logged and the last good rules stay active.
361
+ - **Audit records are write-once**: a result can be posted once, never for a denied call, and never
362
+ while the call is still awaiting approval. Each approval can be decided only once. If two approvers
363
+ click at the same moment, only the first decision counts.
364
+ - **Upgrades**: new columns are added to an existing database automatically at startup.
365
+ - **Redaction**: keys like `password`, `token`, `api_key`, `authorization`, `cookie` and values like
366
+ `Bearer ...`, `sk-...`, `ghp_...` are stored as `[REDACTED]`. Rules still see the raw input.
367
+ - Payloads over `MAX_PAYLOAD_CHARS` are truncated in storage. Proxy responses are buffered (no streaming/SSE).
368
+ - SQLite (WAL) is fine for one machine. For several gateway replicas, set `DATABASE_URL` to Postgres.
369
+
370
+ ## Tests
371
+
372
+ ```bash
373
+ pip install pytest && pytest -q
374
+ python tests/e2e_business_scenario.py
375
+ ```
376
+
377
+ ## Contributing, security, license
378
+
379
+ - [CONTRIBUTING.md](CONTRIBUTING.md): setup and guidelines
380
+ - [SECURITY.md](SECURITY.md): report vulnerabilities privately
381
+ - Licensed under the [Apache License 2.0](LICENSE)