integrity-killswitch 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.
- integrity_killswitch-0.3.0/LICENSE +21 -0
- integrity_killswitch-0.3.0/PKG-INFO +356 -0
- integrity_killswitch-0.3.0/README.md +325 -0
- integrity_killswitch-0.3.0/agent_killswitch/__init__.py +63 -0
- integrity_killswitch-0.3.0/agent_killswitch/__main__.py +10 -0
- integrity_killswitch-0.3.0/agent_killswitch/ancestry.py +767 -0
- integrity_killswitch-0.3.0/agent_killswitch/cloud.py +477 -0
- integrity_killswitch-0.3.0/agent_killswitch/core.py +1214 -0
- integrity_killswitch-0.3.0/agent_killswitch/hooks.py +748 -0
- integrity_killswitch-0.3.0/agent_killswitch/mcp_server.py +551 -0
- integrity_killswitch-0.3.0/agent_killswitch/network.py +1442 -0
- integrity_killswitch-0.3.0/agent_killswitch/web.py +426 -0
- integrity_killswitch-0.3.0/integrity_killswitch.egg-info/PKG-INFO +356 -0
- integrity_killswitch-0.3.0/integrity_killswitch.egg-info/SOURCES.txt +22 -0
- integrity_killswitch-0.3.0/integrity_killswitch.egg-info/dependency_links.txt +1 -0
- integrity_killswitch-0.3.0/integrity_killswitch.egg-info/entry_points.txt +2 -0
- integrity_killswitch-0.3.0/integrity_killswitch.egg-info/top_level.txt +1 -0
- integrity_killswitch-0.3.0/pyproject.toml +60 -0
- integrity_killswitch-0.3.0/setup.cfg +4 -0
- integrity_killswitch-0.3.0/tests/test_cloud.py +370 -0
- integrity_killswitch-0.3.0/tests/test_hooks.py +359 -0
- integrity_killswitch-0.3.0/tests/test_killswitch.py +572 -0
- integrity_killswitch-0.3.0/tests/test_mcp_server.py +409 -0
- integrity_killswitch-0.3.0/tests/test_network.py +610 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 BlackBadHope
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: integrity-killswitch
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: OS process-tree killswitch, 1-command hook auto-installer, Cloud PANIC sync, and OS network/ACL/freeze cutoff for autonomous AI coding agents.
|
|
5
|
+
Author: BlackBadHope
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/BlackBadHope/agent-killswitch
|
|
8
|
+
Project-URL: Repository, https://github.com/BlackBadHope/agent-killswitch
|
|
9
|
+
Project-URL: Issues, https://github.com/BlackBadHope/agent-killswitch/issues
|
|
10
|
+
Keywords: ai-agents,claude-code,codex,cursor,antigravity,killswitch,firewall,security,governance
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Intended Audience :: System Administrators
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
17
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
18
|
+
Classifier: Operating System :: MacOS
|
|
19
|
+
Classifier: Programming Language :: Python :: 3
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
25
|
+
Classifier: Topic :: Security
|
|
26
|
+
Classifier: Topic :: System :: Systems Administration
|
|
27
|
+
Requires-Python: >=3.10
|
|
28
|
+
Description-Content-Type: text/markdown
|
|
29
|
+
License-File: LICENSE
|
|
30
|
+
Dynamic: license-file
|
|
31
|
+
|
|
32
|
+
# integrity-killswitch (`agent-killswitch` CLI)
|
|
33
|
+
|
|
34
|
+
[](https://github.com/BlackBadHope/agent-killswitch/actions/workflows/ci.yml)
|
|
35
|
+
|
|
36
|
+
**An OS process-tree emergency killswitch, Cloud PANIC sync gate, and OS firewall/ACL/freeze cutoff for autonomous AI coding agents** (Claude Code, Codex CLI, Cursor, Gemini CLI, Antigravity, Aider, Copilot, Windsurf, Grok).
|
|
37
|
+
|
|
38
|
+
> **PyPI Package Name Warning:** The official PyPI distribution name for this project is **`integrity-killswitch`** (CLI binary: `agent-killswitch`, Python import: `agent_killswitch`). **Do NOT install the unrelated third-party `agent-killswitch` package on PyPI** — that namespace belongs to an unrelated author.
|
|
39
|
+
|
|
40
|
+
- **Zero runtime dependencies** — pure Python 3.10+ standard library.
|
|
41
|
+
- **Tighten-only for agents, owner-only restore:** any agent or script can hit `panic`, `net-cut`, `freeze`, or disable a vendor/scope, but `resume`, `on`, `scope-on`, `net-restore`, `thaw`, and `uninstall-hooks` walk the OS process tree and **refuse (exit `3`)** whenever an LLM ancestor or orphaned shell is detected. `--vendor` can never override an OS-detected LLM vendor.
|
|
42
|
+
- **1-Command Hook Auto-Installer (Fail-Closed Exit `2` + Vendor JSON):** `agent-killswitch install-hooks --all` safely patches Claude Code, Codex CLI, Cursor, Gemini CLI, and Antigravity using each client's exact native schema, UTF-8 BOM-safe JSON parsing, dynamic executable resolution (`agent-killswitch` or `"<python>" -m agent_killswitch`), explicit hardened `--state` embedding, and `--hook-format <vendor>` (`exit 2` + vendor-specific blocking JSON on stdout).
|
|
43
|
+
- **Cloud Control Plane PANIC Sync (`cloud-sync`):** polls `GET <cloud_url>/api/v1/killswitch/state` (stdlib `urllib.request`, 3s timeout, TTL-cached every 15s during `check`) and immediately latches local `state.json` Master Panic when the Cloud Dashboard's Big Red PANIC button is pressed.
|
|
44
|
+
- **Absolute OS Killswitch:** `agent-killswitch panic --network --freeze` combines `state.json` Master Panic, kernel-level outbound **TCP + UDP 80/443 (HTTP/HTTPS/QUIC)** LLM API firewall cutoff (`nftables`/`iptables`/`netsh`+PowerShell/`pf`) with anti-lockout rules, and POSIX `SIGSTOP` process-tree freeze — plus `agent-killswitch harden` defaulting to system-owned paths (`/etc/agent-killswitch/state.json` / `C:\ProgramData\agent-killswitch\state.json`) with locale-independent Windows SIDs.
|
|
45
|
+
- **Fail-closed:** corrupt or unreadable state defaults to Master Panic active.
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
## 60-Second Install (PEP 668 & Windows `pwsh 7` Safe)
|
|
50
|
+
|
|
51
|
+
Modern Debian/Ubuntu 24.04+ enforces PEP 668 (`externally-managed-environment`). Never pass `--break-system-packages`. Use zero-install or an isolated `.venv`:
|
|
52
|
+
|
|
53
|
+
### Option A: Zero-Install Direct Run (Linux / macOS / Windows)
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
git clone https://github.com/BlackBadHope/agent-killswitch
|
|
57
|
+
cd agent-killswitch
|
|
58
|
+
python3 killswitch.py status
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Option B: Isolated `.venv` Install (Linux / macOS — PEP 668 Safe)
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
git clone https://github.com/BlackBadHope/agent-killswitch
|
|
65
|
+
cd agent-killswitch
|
|
66
|
+
python3 -m venv .venv
|
|
67
|
+
.venv/bin/python -m pip install --no-deps .
|
|
68
|
+
.venv/bin/agent-killswitch status
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Option C: Windows PowerShell 7 (`pwsh 7`)
|
|
72
|
+
|
|
73
|
+
> **Use PowerShell 7 (`pwsh 7`), not legacy Windows PowerShell 5.1**, when installing hooks or running elevated firewall/ACL commands to avoid UTF-8 BOM and argument-quoting drift.
|
|
74
|
+
|
|
75
|
+
```powershell
|
|
76
|
+
git clone https://github.com/BlackBadHope/agent-killswitch
|
|
77
|
+
cd agent-killswitch
|
|
78
|
+
python -m venv .venv
|
|
79
|
+
.\.venv\Scripts\python.exe -m pip install --no-deps .
|
|
80
|
+
.\.venv\Scripts\agent-killswitch.exe status
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
*(When installing from PyPI once published, install **`integrity-killswitch`** — never `agent-killswitch`.)*
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## Honest Threat Model: User-Level vs Elevated-Privilege Enforcement
|
|
88
|
+
|
|
89
|
+
Security tools lose trust when they claim magic. Here is what each layer enforces — and where its boundary is:
|
|
90
|
+
|
|
91
|
+
| Layer | Privilege Required | What It Stops | Boundary / Bypass |
|
|
92
|
+
| :--- | :--- | :--- | :--- |
|
|
93
|
+
| **1. Hooks & Process Ancestry** (`install-hooks`, `check --hook-format`, `panic`, `resume`) | None (normal user) | Accidental tool calls, prompt-injected deploys/pushes, `--vendor` spoofing, and agents trying to `resume` or `on` themselves via subprocesses or detached shells | A rogue same-user process that ignores client hooks can overwrite a user-writable `~/.agent-killswitch/state.json` or call LLM APIs directly |
|
|
94
|
+
| **2. System-Owned State ACL Hardening** (`harden`) | Root / Administrator (once) | Same-user rogue agent editing, truncating, deleting, or `mv`-swapping state (`root:root 0755/0644` in `/etc/agent-killswitch/state.json` on POSIX; universal SIDs `*S-1-5-32-544` / `*S-1-5-18` / `*S-1-5-32-545` in `C:\ProgramData\agent-killswitch\state.json` on Windows) | Does not stop an agent from ignoring hook wrappers if it executes tools outside hooked paths |
|
|
95
|
+
| **3. Absolute OS Cutoff** (`net-cut`, `freeze`, `panic --network --freeze`) | Root / Administrator for firewall; same user for POSIX `SIGSTOP` | Even if a same-user rogue agent ignores hooks completely, outbound **TCP & UDP 80/443 (including QUIC / HTTP/3)** to LLM API providers is rejected at the OS firewall and POSIX agent process trees (parents + children) are frozen (`SIGSTOP`) | Requires elevation to apply/remove firewall rules. On **Windows**, live `freeze`/`thaw` honestly returns `ok: false, supported: false` (exit `1`) and prints a safe `pssuspend` / `Stop-Process` plan rather than pretending success |
|
|
96
|
+
| **4. Cloud Control Plane Sync** (`cloud-sync`, `check --cloud-url`) | License / agent key | Remote fleet Master Panic, per-vendor off, and per-scope off pushed from the dashboard latch locally on next `cloud-sync` or `check` TTL refresh | Offline hosts fall back to local + last cached remote state unless `--cloud-fail-closed` is passed |
|
|
97
|
+
| **5. Root / Admin Compromised Host** | External control plane | Nothing local can contain an attacker who already owns `root` / `SYSTEM` | Pair with the external **Integrity Cloud Control Plane** ([integrity.subnet.zp.ua](https://integrity.subnet.zp.ua)) for server-side key revocation and SHA-256 Cloud Witness notarization |
|
|
98
|
+
|
|
99
|
+
### Process-Ancestry Caller Detection Details
|
|
100
|
+
|
|
101
|
+
- **Windows:** walks Win32 `CreateToolhelp32Snapshot`, bridges Git/MSYS `fork/exec` chains via `ps.exe`, and detects browser clients on `127.0.0.1` via `GetExtendedTcpTable`. Orphaned shells (`Start-Process pwsh` whose parent exited) fail closed as `unknown_llm`.
|
|
102
|
+
- **Linux:** walks `/proc/<pid>/stat`, `exe`, `comm`, and `cmdline` up to PID `1`, checks start times against PID reuse, and re-validates the full chain on a second pass. Detached `tmux`/`screen` shells and non-interactive SSH commands fail closed as `unknown_llm`; interactive human SSH logins (`sshd`/`sshd-session` + `SSH_TTY` + live TTY) are recognized as `owner`.
|
|
103
|
+
- **macOS:** walks `/bin/ps -axo pid=,ppid=,comm=` up to `launchd` (PID `1`) and resolves loopback dashboard peers via `/usr/sbin/lsof` (no `sudo` required).
|
|
104
|
+
- **Anti-spoofing (`--vendor`):** `check` ALWAYS runs OS ancestry detection first; `--vendor` can never downgrade an OS-detected LLM vendor (e.g., a `claude` process passing `--vendor codex` or `--vendor owner` is still evaluated as `claude`).
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## Core Commands
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
# Inspect state and see how your current shell is classified (zero-write)
|
|
112
|
+
agent-killswitch status
|
|
113
|
+
agent-killswitch status --json
|
|
114
|
+
|
|
115
|
+
# MASTER RED BUTTON: immediately block all AI agents
|
|
116
|
+
agent-killswitch panic --reason "unexpected prod diff"
|
|
117
|
+
|
|
118
|
+
# Disable one vendor or one action scope
|
|
119
|
+
agent-killswitch off claude --reason "investigating loop"
|
|
120
|
+
agent-killswitch scope-off deploy
|
|
121
|
+
|
|
122
|
+
# Gate any script or deploy wrapper (default: exit 0 allowed, exit 3 refused)
|
|
123
|
+
agent-killswitch check --action deploy --target prod-api
|
|
124
|
+
|
|
125
|
+
# Gate AI client hooks (exit 2 + vendor-specific blocking JSON on stdout)
|
|
126
|
+
agent-killswitch check --hook-format claude --action deploy
|
|
127
|
+
agent-killswitch check --hook-format cursor
|
|
128
|
+
agent-killswitch check --hook-format antigravity
|
|
129
|
+
|
|
130
|
+
# Restore access (MUST be run by the human owner in an interactive shell or browser)
|
|
131
|
+
agent-killswitch resume
|
|
132
|
+
agent-killswitch on claude
|
|
133
|
+
|
|
134
|
+
# Launch the localhost-only Web UI dashboard (Same-Origin + peer-PID verified)
|
|
135
|
+
agent-killswitch serve --port 8787
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
### `--hook-format` Refusal Matrix
|
|
139
|
+
|
|
140
|
+
| `--hook-format` | Refusal Exit Code | Stdout Blocking JSON |
|
|
141
|
+
| :--- | :--- | :--- |
|
|
142
|
+
| `none` *(default)* | `3` (`EXIT_REFUSED`) | *(none; refusal reason on stderr — 100% backwards compatible)* |
|
|
143
|
+
| `claude` / `codex` / `gemini` | `2` (`EXIT_HOOK_BLOCK`) | `{"decision":"block","reason":"..."}` |
|
|
144
|
+
| `antigravity` | `2` (`EXIT_HOOK_BLOCK`) | `{"decision":"deny","reason":"..."}` |
|
|
145
|
+
| `cursor` | `2` (`EXIT_HOOK_BLOCK`) | `{"continue":false,"permission":"deny","userMessage":"..."}` |
|
|
146
|
+
|
|
147
|
+
---
|
|
148
|
+
|
|
149
|
+
## MCP Server (stdio)
|
|
150
|
+
|
|
151
|
+
Run a **zero-dependency Python stdlib** JSON-RPC 2.0 MCP server over `stdio` so AI coding clients can inspect killswitch state or trip an emergency cutoff directly:
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
# Installed CLI, zero-install shim, or Python module entry point
|
|
155
|
+
agent-killswitch mcp-serve
|
|
156
|
+
python killswitch.py mcp-serve
|
|
157
|
+
python -m agent_killswitch.mcp_server
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
**Tighten-Only Security Invariant:** MCP exposes ONLY read and tighten tools (`killswitch_status`, `killswitch_check`, `killswitch_panic`, `killswitch_vendor_off`, `killswitch_scope_off`). Restore operations (`resume`, `on`, `scope-on`, `net-restore`, `thaw`, `uninstall-hooks`) are **never** exposed over MCP and require the human owner in an interactive shell or the localhost Web UI.
|
|
161
|
+
|
|
162
|
+
### Claude Code / Cursor / Antigravity MCP Config
|
|
163
|
+
|
|
164
|
+
Add to `~/.claude.json` (or `.mcp.json`), `~/.cursor/mcp.json`, or `~/.gemini/antigravity/mcp_config.json` (pointing to your local clone or `.venv` Python):
|
|
165
|
+
|
|
166
|
+
```json
|
|
167
|
+
{
|
|
168
|
+
"mcpServers": {
|
|
169
|
+
"agent-killswitch": {
|
|
170
|
+
"command": "python",
|
|
171
|
+
"args": ["-m", "agent_killswitch.mcp_server"],
|
|
172
|
+
"env": {
|
|
173
|
+
"PYTHONPATH": "/path/to/agent-killswitch"
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
*(If installed into a `.venv` via `pip install --no-deps .`, set `"command"` to your `.venv` Python executable and omit `"PYTHONPATH"`. Pass `["-m", "agent_killswitch.mcp_server", "--state", "/etc/agent-killswitch/state.json"]` to bind to a hardened state file.)*
|
|
181
|
+
|
|
182
|
+
---
|
|
183
|
+
|
|
184
|
+
## Cloud Control Plane PANIC Sync (`cloud-sync`)
|
|
185
|
+
|
|
186
|
+
Connect local `agent-killswitch` to the Integrity Cloud Control Plane ([https://integrity.subnet.zp.ua](https://integrity.subnet.zp.ua)) so pressing the Dashboard's **Big Red PANIC** button halts local agents automatically:
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
# One-shot sync (fetches GET <cloud_url>/api/v1/killswitch/state, 3s timeout)
|
|
190
|
+
export INTEGRITY_CLOUD_URL="https://integrity.subnet.zp.ua"
|
|
191
|
+
export INTEGRITY_LICENSE_KEY="IHA-your-scoped-agent-key"
|
|
192
|
+
agent-killswitch cloud-sync --json
|
|
193
|
+
|
|
194
|
+
# Or pass flags directly (license key is never written to logs or cache files)
|
|
195
|
+
agent-killswitch cloud-sync \
|
|
196
|
+
--cloud-url https://integrity.subnet.zp.ua \
|
|
197
|
+
--license-key "$INTEGRITY_LICENSE_KEY"
|
|
198
|
+
|
|
199
|
+
# Automatic TTL-cached sync inside `check` (refreshes every INTEGRITY_CLOUD_TTL seconds, default 15s)
|
|
200
|
+
agent-killswitch check --hook-format claude
|
|
201
|
+
|
|
202
|
+
# Optional strict mode: refuse actions if Cloud Control Plane is unreachable
|
|
203
|
+
agent-killswitch check --hook-format claude --cloud-fail-closed
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
- When remote `master_panic == true`, `cloud-sync` (and `check`) **immediately latches local `state.json`** (`master_panic: true`) and caches `disabled_vendors` and `disabled_scopes` locally.
|
|
207
|
+
- When offline, `check` fails safe by enforcing local `state.json` + the last cached remote state (or refuses immediately with `--cloud-fail-closed`).
|
|
208
|
+
|
|
209
|
+
---
|
|
210
|
+
|
|
211
|
+
## 1-Command Hook Auto-Installer (`install-hooks` / `uninstall-hooks`)
|
|
212
|
+
|
|
213
|
+
Wire all 5 supported AI coding agents in one command without hand-editing JSON:
|
|
214
|
+
|
|
215
|
+
```bash
|
|
216
|
+
# Preview changes safely (zero writes, zero backups created)
|
|
217
|
+
agent-killswitch install-hooks --all --dry-run
|
|
218
|
+
|
|
219
|
+
# Install fail-closed exit-2 hooks across Claude Code, Codex CLI, Cursor, Gemini CLI, and Antigravity
|
|
220
|
+
agent-killswitch install-hooks --all
|
|
221
|
+
|
|
222
|
+
# Or target specific clients with an explicit hardened state path (blocks AGENT_KILLSWITCH_STATE bypass)
|
|
223
|
+
agent-killswitch install-hooks --claude --cursor --gemini --state /etc/agent-killswitch/state.json
|
|
224
|
+
|
|
225
|
+
# Cleanly remove ONLY agent-killswitch entries (owner-only, preserves all other hooks)
|
|
226
|
+
agent-killswitch uninstall-hooks --all
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
| Target Flag | Client | Config Path | Native Schema Managed |
|
|
230
|
+
| :--- | :--- | :--- | :--- |
|
|
231
|
+
| `--claude` | Claude Code | `~/.claude/settings.json` | `hooks.PreToolUse` (`matcher: ".*"`, `--hook-format claude`) |
|
|
232
|
+
| `--codex` | Codex CLI | `~/.codex/hooks.json` | `hooks.PreToolUse` (`matcher: ".*"`, `--hook-format codex`) |
|
|
233
|
+
| `--cursor` | Cursor | `~/.cursor/hooks.json` | `hooks.preToolUse`, `hooks.beforeShellExecution`, `hooks.beforeMCPExecution` (`failClosed: true`, `--hook-format cursor`) |
|
|
234
|
+
| `--gemini` | Gemini CLI | `~/.gemini/settings.json` | `hooks.BeforeTool` (`matcher: ".*"`, `--hook-format gemini`) |
|
|
235
|
+
| `--antigravity` | Antigravity | `~/.gemini/config/hooks.json` | Top-level `"agent-killswitch": {"PreToolUse": [...]}` (`matcher: ".*"`, `--hook-format antigravity`) |
|
|
236
|
+
|
|
237
|
+
Safety guarantees:
|
|
238
|
+
- Reads JSON with `utf-8-sig` (handles Windows UTF-8 BOM files without crashing).
|
|
239
|
+
- Resolves the executable dynamically: emits `agent-killswitch` only when on `PATH`, otherwise `"<sys.executable>" -m agent_killswitch`.
|
|
240
|
+
- Automatically embeds `--state "<hardened_path>"` when `--state` is passed or when the OS hardened state file exists (`/etc/agent-killswitch/state.json` or `C:\ProgramData\agent-killswitch\state.json`).
|
|
241
|
+
- Creates a timestamped `.bak` copy next to any existing file before patching, preserves unrelated hooks/settings, and stays idempotent on re-run.
|
|
242
|
+
- `uninstall-hooks` is **owner-only** (`exit 3` if invoked by an LLM agent).
|
|
243
|
+
|
|
244
|
+
---
|
|
245
|
+
|
|
246
|
+
## Absolute Killswitch (OS Network Cutoff + ACL + Freeze)
|
|
247
|
+
|
|
248
|
+
When cooperative hooks are not enough, escalate to OS-level enforcement:
|
|
249
|
+
|
|
250
|
+
```bash
|
|
251
|
+
# 1-command ABSOLUTE KILLSWITCH: Master Panic + OS LLM API firewall cutoff + POSIX SIGSTOP freeze
|
|
252
|
+
sudo agent-killswitch panic --network --freeze --reason "runaway agent loop"
|
|
253
|
+
|
|
254
|
+
# Inspect whether OS network cutoff rules are active (strictly zero-write)
|
|
255
|
+
agent-killswitch net-status --json
|
|
256
|
+
|
|
257
|
+
# Preview any OS cutoff, ACL hardening, or freeze plan safely before applying
|
|
258
|
+
agent-killswitch net-cut --dry-run
|
|
259
|
+
agent-killswitch freeze --dry-run
|
|
260
|
+
agent-killswitch harden --dry-run
|
|
261
|
+
|
|
262
|
+
# Owner-only full restore (refuses with exit 3 if called by any LLM agent!)
|
|
263
|
+
sudo agent-killswitch resume --network --thaw
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
### OS Network Cutoff (`net-cut` / `net-restore` / `net-status`)
|
|
267
|
+
|
|
268
|
+
Blocks outbound **TCP and UDP `80`/`443` (closing HTTP/HTTPS and QUIC / HTTP/3)** to known LLM API providers (`api.anthropic.com`, `api.openai.com`, `generativelanguage.googleapis.com`, `cloudcode-pa.googleapis.com`, `api2.cursor.sh`, `api.githubcopilot.com`, `openrouter.ai`, `api.x.ai`, `api.mistral.ai`, `api.deepseek.com`) plus any extra hosts in `--endpoints-file PATH`:
|
|
269
|
+
|
|
270
|
+
- **Linux:** applies an isolated `nftables` table `inet agent_killswitch_net` (`meta l4proto { tcp, udp } th dport { 80, 443 } reject`), with dedicated `iptables`/`ip6tables` chain `AGENT_KILLSWITCH_OUT` TCP+UDP fallback.
|
|
271
|
+
- **Windows (Locale-Independent — works on EN/RU/UK/DE/FR Windows):** adds Windows Firewall outbound TCP + UDP block rules prefixed `AgentKillswitch_Block_` via `netsh advfirewall` (plus optional `--block-binaries PATH`), and inspects/removes them via PowerShell `Get-NetFirewallRule` / `Remove-NetFirewallRule` (zero English text parsing).
|
|
272
|
+
- **macOS:** loads a dedicated `pf` anchor `com.agent-killswitch/cutoff` (`block return out quick proto { tcp, udp } to <ak_block> port { 80, 443 }`) and flushes active states (`pfctl -k`).
|
|
273
|
+
- **Anti-Lockout Guarantee:** loopback (`127.0.0.0/8`, `::1`), SSH (`TCP 22`), DNS (`UDP/TCP 53`), `integrity.subnet.zp.ua`, and any `--allow-host HOST` are **ALWAYS** explicitly allowed and stripped from block sets.
|
|
274
|
+
- **`net-restore` is OWNER-ONLY:** fails closed (`exit 3`) if invoked by any LLM agent.
|
|
275
|
+
|
|
276
|
+
### Process Freeze & Thaw (`freeze` / `thaw`)
|
|
277
|
+
|
|
278
|
+
```bash
|
|
279
|
+
# Freeze running AI agent process trees (parents + child processes on POSIX)
|
|
280
|
+
agent-killswitch freeze --vendor claude
|
|
281
|
+
|
|
282
|
+
# Resume frozen agent processes (OWNER-ONLY — exit 3 for LLM callers)
|
|
283
|
+
agent-killswitch thaw --vendor claude
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
- Matches **only** executable basenames and interpreter script paths (never substring-matches arbitrary CLI arguments like `vim claude.md`), includes descendant child processes on POSIX, and excludes self, parent shells, owner terminals, browsers, and `sshd`.
|
|
287
|
+
- Sends POSIX `SIGSTOP`/`SIGCONT` on Linux and macOS. On Windows, `--dry-run` returns `ok: true, supported: false` with a `pssuspend` plan; live `freeze`/`thaw` honestly returns `ok: false, supported: false` (exit `1`) rather than claiming processes were frozen.
|
|
288
|
+
|
|
289
|
+
### OS-Level State ACL Hardening (`harden`)
|
|
290
|
+
|
|
291
|
+
Defaults to a system-owned root directory (eliminating `mv ~/.agent-killswitch` swap bypasses and keeping user `~/.agent-killswitch/audit.jsonl` writable):
|
|
292
|
+
|
|
293
|
+
```bash
|
|
294
|
+
# Linux / macOS: defaults to /etc/agent-killswitch/state.json (root:root or root:wheel 0755/0644)
|
|
295
|
+
sudo agent-killswitch harden
|
|
296
|
+
|
|
297
|
+
# Windows (elevated pwsh 7): defaults to C:\ProgramData\agent-killswitch\state.json
|
|
298
|
+
# Uses universal locale-independent SIDs (*S-1-5-32-544, *S-1-5-18, *S-1-5-32-545)
|
|
299
|
+
agent-killswitch harden
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
---
|
|
303
|
+
|
|
304
|
+
## OpenSSH `Match exec` & Python API Examples
|
|
305
|
+
|
|
306
|
+
```sshconfig
|
|
307
|
+
Match host prod-* exec "agent-killswitch check --action ssh --target %h --match-blocked"
|
|
308
|
+
ProxyCommand /bin/false
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
```python
|
|
312
|
+
from agent_killswitch import check_or_refuse
|
|
313
|
+
|
|
314
|
+
check_or_refuse(action="secrets", target="prod-db-password")
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
---
|
|
318
|
+
|
|
319
|
+
## Clean Uninstall / Reset-to-Zero
|
|
320
|
+
|
|
321
|
+
`integrity-killswitch` installs no background daemons, services, or kernel drivers:
|
|
322
|
+
|
|
323
|
+
```bash
|
|
324
|
+
# Linux / macOS
|
|
325
|
+
agent-killswitch uninstall-hooks --all
|
|
326
|
+
python3 -m pip uninstall -y integrity-killswitch 2>/dev/null || true
|
|
327
|
+
rm -rf ~/.agent-killswitch
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
```powershell
|
|
331
|
+
# Windows (PowerShell 7)
|
|
332
|
+
agent-killswitch uninstall-hooks --all
|
|
333
|
+
python -m pip uninstall -y integrity-killswitch
|
|
334
|
+
Remove-Item -Recurse -Force "$HOME\.agent-killswitch" -ErrorAction SilentlyContinue
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
---
|
|
338
|
+
|
|
339
|
+
## Development & Tests
|
|
340
|
+
|
|
341
|
+
```bash
|
|
342
|
+
ruff check agent_killswitch killswitch.py tests agensi-skill/scripts
|
|
343
|
+
python -m pytest -q
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
## Full Production Suite & Cloud Control Plane
|
|
347
|
+
|
|
348
|
+
`integrity-killswitch` is the free open-source foundation of the **Integrity Harness** ecosystem:
|
|
349
|
+
|
|
350
|
+
- **Cloud Control Plane (Hybrid SaaS):** [integrity.subnet.zp.ua](https://integrity.subnet.zp.ua) — tamper-evident SHA-256 Cloud Witness notarization, central multi-host Killswitch PANIC API, and team license management.
|
|
351
|
+
- **1-Click MCP Skills & Paid Packs (Agensi Storefront):** [agensi.io/r/BLACKHOPE](https://www.agensi.io/r/BLACKHOPE)
|
|
352
|
+
- **Free Companion OSS Tool:** [BlackBadHope/agent-token-forensics](https://github.com/BlackBadHope/agent-token-forensics) — read-only JSONL token, prompt-cache, and retry-loop forensics across Claude Code, Codex CLI, Cursor, and Gemini.
|
|
353
|
+
|
|
354
|
+
## License
|
|
355
|
+
|
|
356
|
+
MIT — see [LICENSE](LICENSE).
|