@clawdreyhepburn/carapace 0.3.0 → 0.3.2

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.
package/README.md CHANGED
@@ -2,38 +2,122 @@
2
2
  <h1 align="center">🦞 Carapace</h1>
3
3
  <p align="center"><strong>Your agent's exoskeleton.</strong></p>
4
4
  <p align="center">
5
- Immutable policy boundaries for MCP tool access.<br>
6
- Powered by <a href="https://www.cedarpolicy.com/">Cedar</a> +
7
- <a href="https://github.com/JanssenProject/jans/tree/main/jans-cedarling">Cedarling WASM</a>.
5
+ Controls what your AI agent can do — which tools it can use, which commands it can run, and which websites it can talk to. If a policy says no, the agent can't do it.
8
6
  </p>
9
7
  <p align="center">
8
+ <a href="#how-it-works">How It Works</a> •
10
9
  <a href="#installation">Installation</a> •
11
10
  <a href="#quick-start">Quick Start</a> •
12
- <a href="#how-it-works">How It Works</a> •
11
+ <a href="docs/SECURITY.md">Security Guide</a> •
13
12
  <a href="docs/RECOMMENDED-POLICIES.md">Recommended Policies</a> •
14
- <a href="#gui">Control GUI</a> •
15
- <a href="#security">Security</a> •
13
+ <a href="#the-control-gui">Control GUI</a> •
16
14
  <a href="#attribution">Attribution</a>
17
15
  </p>
18
16
  </p>
19
17
 
20
18
  ---
21
19
 
22
- Carapace is an [OpenClaw](https://github.com/openclaw/openclaw) plugin that puts Cedar authorization between your AI agent and everything it can do — MCP tools, shell commands, and outbound API calls. It aggregates multiple MCP servers, discovers their tools, gates shell execution by binary name, controls outbound HTTP by domain, and enforces [Cedar](https://www.cedarpolicy.com/) policies on every operation — with a local GUI where humans can see and control everything.
20
+ ## What is Carapace?
23
21
 
24
- **The problem:** Agents have access to tools, a shell, and the network. But who decides what they can actually *do*? Today the answer is "whatever's in the config file" a static, all-or-nothing list with no audit trail, no formal guarantees, and no human oversight.
22
+ AI agents can do a lot. They can read and write files, run shell commands, call APIs, send emails, push code anything you give them access to. That's powerful, but it's also dangerous. An agent that can delete files can delete *all* files. An agent that can call APIs can send your data anywhere.
25
23
 
26
- **The solution:** Carapace puts Cedar between your agent and its capabilities. Cedar policies are declarative, auditable, and formally verifiable. The local GUI makes it accessible to humans who don't want to write policy files by hand. Toggle a switch, and the Cedar policy updates. It's that simple.
24
+ **Carapace is a security layer that controls what your agent is allowed to do.** You write rules (called policies) that say things like "this agent can read files but not delete them" or "this agent can use git but not run sudo." Carapace enforces those rules on every single action the agent takes.
27
25
 
28
- ## Design Philosophy
26
+ It works as a plugin for [OpenClaw](https://github.com/openclaw/openclaw) (an open-source AI agent platform), but the concepts apply to any agent system.
27
+
28
+ ### What does it control?
29
+
30
+ Carapace gates three types of operations:
31
+
32
+ | What | How it works | Example |
33
+ |------|-------------|---------|
34
+ | **MCP tools** | Your agent connects to external tool servers (file system, GitHub, databases) via [MCP](https://modelcontextprotocol.io/). Carapace checks each tool call against your policies before it reaches the server. | Allow `read_file`, block `write_file` |
35
+ | **Shell commands** | Your agent runs commands on your computer. Carapace checks which program the agent is trying to run. | Allow `git` and `ls`, block `rm` and `sudo` |
36
+ | **API calls** | Your agent makes HTTP requests to websites and services. Carapace checks which domain the agent is trying to reach. | Allow `api.github.com`, block `pastebin.com` |
37
+
38
+ ### What is Cedar?
39
+
40
+ [Cedar](https://www.cedarpolicy.com/) is a policy language created by AWS. Instead of configuring permissions in a settings file or a database, you write human-readable rules like this:
41
+
42
+ ```cedar
43
+ // Let the agent use git
44
+ permit(
45
+ principal is Jans::Workload,
46
+ action == Jans::Action::"exec_command",
47
+ resource == Jans::Shell::"git"
48
+ );
49
+
50
+ // Never let the agent delete files
51
+ forbid(
52
+ principal,
53
+ action == Jans::Action::"exec_command",
54
+ resource == Jans::Shell::"rm"
55
+ );
56
+ ```
57
+
58
+ Cedar has one critical property: **forbid always wins.** If any rule says "no," the action is blocked — no matter how many other rules say "yes." This means you can't accidentally create a loophole by adding a new "allow" rule that overrides your safety restrictions.
59
+
60
+ Carapace uses [Cedarling](https://github.com/JanssenProject/jans/tree/main/jans-cedarling), a high-performance Cedar engine compiled to WebAssembly, so policy checks run in under 6 milliseconds.
61
+
62
+ ### What is OpenClaw?
63
+
64
+ [OpenClaw](https://github.com/openclaw/openclaw) is an open-source platform for running AI agents. It connects AI models (like Claude or GPT) to messaging apps, tools, and services. Think of it as the runtime that makes your agent work. Carapace plugs into OpenClaw to add authorization — controlling what the agent is allowed to do within that runtime.
65
+
66
+ ### What is MCP?
67
+
68
+ [MCP (Model Context Protocol)](https://modelcontextprotocol.io/) is an open standard for connecting AI agents to tools. An MCP server provides tools (like "read a file" or "search a database"), and the agent calls those tools to get work done. Carapace sits between the agent and the MCP servers, checking every tool call against your policies.
69
+
70
+ ---
71
+
72
+ ## How It Works
73
+
74
+ Carapace has two enforcement modes. You can use either or both.
75
+
76
+ ### Mode 1: LLM Proxy (recommended — strongest protection)
77
+
78
+ This is the most secure setup. Here's what happens:
79
+
80
+ 1. Your agent talks to an AI model (like Claude) to figure out what to do.
81
+ 2. The AI model responds with instructions like "call the `exec` tool with command `rm -rf /tmp`."
82
+ 3. **Normally**, your agent platform would immediately execute that instruction.
83
+ 4. **With Carapace**, the AI model's response goes through Carapace first. Carapace reads every tool call in the response, checks it against your Cedar policies, and **removes any tool calls that aren't allowed.**
84
+ 5. Your agent platform only sees the filtered response — it never even knows the AI tried to do something forbidden.
85
+
86
+ This works because Carapace intercepts the response before your agent platform processes it. The `setup` command automatically points your provider at Carapace's local proxy, so all LLM traffic flows through Cedar.
87
+
88
+ ```
89
+ Your agent → Carapace proxy (localhost) → Anthropic/OpenAI API
90
+
91
+ Cedar checks each
92
+ tool call in the
93
+ AI's response
94
+
95
+ Denied calls are
96
+ removed before your
97
+ agent sees them
98
+ ```
29
99
 
30
- **Installing Carapace should never break your agent.** The default policy is `allow-all` — every tool works exactly as before. Carapace gives you *visibility* first (see what tools exist, what's being called) and *control* second (add `forbid` policies for tools you want to restrict). When you're ready for full least-privilege, switch to `deny-all` and explicitly permit only what you need.
100
+ **Supports:** Anthropic (Claude) and OpenAI (GPT) APIs, both streaming and non-streaming.
31
101
 
32
- The progression:
33
- 1. **Install** → everything works, you can see all tools in the GUI
34
- 2. **Observe** watch what your agent uses, understand the tool landscape
35
- 3. **Restrict** → forbid dangerous tools (write, execute) you don't want
36
- 4. **Lock down** switch to `deny-all` for full least-privilege (optional)
102
+ ### Mode 2: Tool-level gating (simpler, weaker)
103
+
104
+ Carapace registers its own versions of common tools (`carapace_exec` for shell commands, `carapace_fetch` for API calls, `mcp_call` for MCP tools). These check Cedar policies before doing anything. You then disable the built-in versions so the agent is forced to use Carapace's gated versions.
105
+
106
+ This is simpler to set up but weaker — it relies on the agent using the right tools. The LLM proxy is better because it's un-bypassable.
107
+
108
+ ### The Control GUI
109
+
110
+ Carapace includes a web dashboard (runs locally on your machine) where you can:
111
+
112
+ - **See all tools** your agent has access to, organized by risk level
113
+ - **Toggle tools on/off** with a switch — each toggle creates a Cedar policy
114
+ - **Build policies visually** using dropdown menus instead of writing Cedar by hand
115
+ - **Edit the Cedar schema** that defines your policy structure
116
+ - **Verify** that all your policies are valid
117
+
118
+ Open it at [http://localhost:19820](http://localhost:19820) after starting Carapace.
119
+
120
+ ---
37
121
 
38
122
  ## Architecture
39
123
 
@@ -64,341 +148,269 @@ The progression:
64
148
  +-------------+
65
149
  ```
66
150
 
67
- ### Two enforcement modes
151
+ **Key components:**
68
152
 
69
- **LLM Proxy (recommended):** Carapace holds the real API key and proxies all LLM traffic. When the LLM suggests a tool call, Carapace evaluates it against Cedar *before returning the response to OpenClaw*. Denied tool calls are stripped from the response — OpenClaw never sees them and can't execute them. **This is un-bypassable.** The agent can't call tools that Cedar denies because it literally never receives the tool call instruction.
153
+ - **LLM Proxy** Sits between your agent and the AI model. Intercepts tool calls in the AI's response and filters out denied ones.
154
+ - **Cedarling WASM** — The Cedar policy engine, running as WebAssembly for near-native speed. This is where your policies are evaluated.
155
+ - **MCP Aggregator** — Connects to your upstream MCP servers, discovers their tools, and proxies calls through Cedar.
156
+ - **Control GUI** — A local web dashboard for managing tools and policies. Single HTML file, no build step, dark theme.
70
157
 
71
- **Tool-level gating:** Carapace registers Cedar-gated agent tools (`carapace_exec`, `carapace_fetch`, `mcp_call`) that authorize each operation before executing it. This requires denying built-in tools via `openclaw carapace setup` to prevent bypass. Use this mode when you can't or don't want to proxy LLM traffic.
158
+ ---
72
159
 
73
160
  ## Screenshots
74
161
 
75
162
  ### Tools Dashboard
76
- The main view shows all discovered MCP tools across all connected servers, with category badges, toggle switches, and smart filtering.
163
+ See all tools across all connected servers. Toggle switches control access. Color-coded by risk level.
77
164
 
78
165
  ![Tools Overview](docs/screenshots/tools-overview.png)
79
166
 
80
- Tools are automatically categorized by risk level:
81
- - ✏️ **Write** (orange) — creates or modifies data
82
- - ⚡ **Execute** (red) — triggers operations, toggles state
83
- - 🔍 **Browse** (blue) — lists, searches, inspects metadata
84
- - 📖 **Read** (teal) — retrieves content, no side effects
85
-
86
- Default sort puts the riskiest tools at the top. Filter by category, status, server, or search.
87
-
88
167
  ### Policy Management
89
- View, edit, and delete Cedar policies. Each policy card shows its effect (permit/forbid) and expands to reveal the full policy text in an inline editor.
168
+ View, edit, and delete Cedar policies. Each card shows permit/forbid and the full policy text.
90
169
 
91
170
  ![Policies Tab](docs/screenshots/policies-tab.png)
92
171
 
93
172
  ### Visual Policy Builder
94
- Build Cedar policies without writing code. Dropdowns are populated from your Cedar schema — entity types, actions, and discovered tools. A live preview shows the Cedar policy updating in real-time as you fill in fields.
173
+ Build policies with dropdown menus instead of writing Cedar. Live preview updates as you go.
95
174
 
96
175
  ![Policy Builder](docs/screenshots/policy-builder.png)
97
176
 
98
177
  ### Schema Editor
99
- View and edit the Cedar schema directly. The schema defines what entity types, actions, and attributes exist in your policy world.
178
+ View and edit the Cedar schema that defines your policy types and actions.
100
179
 
101
180
  ![Schema Tab](docs/screenshots/schema-tab.png)
102
181
 
182
+ ---
183
+
103
184
  ## Installation
104
185
 
105
- ### Prerequisites
186
+ ### What you need
106
187
 
107
188
  - [Node.js](https://nodejs.org/) 20 or later
108
- - [OpenClaw](https://github.com/openclaw/openclaw) (optional Carapace can also run standalone)
189
+ - [OpenClaw](https://github.com/openclaw/openclaw) installed and running
109
190
 
110
- ### As an OpenClaw Plugin
191
+ ### Step 1: Install the plugin
111
192
 
112
193
  ```bash
113
- # Install the plugin
114
- openclaw plugins install @openclaw/carapace
115
-
116
- # Configure your MCP servers
117
- openclaw configure
194
+ openclaw plugins install @clawdreyhepburn/carapace
118
195
  ```
119
196
 
120
- ### Standalone (for development/testing)
197
+ ### Step 2: Choose your enforcement mode
121
198
 
122
- ```bash
123
- git clone https://github.com/clawdreyhepburn/carapace.git
124
- cd carapace
125
- npm install
126
- npx tsx test/harness.ts
127
- # Open http://localhost:19820
128
- ```
199
+ Carapace has two modes. Pick one (or use both for defense in depth).
129
200
 
130
- ## Quick Start
201
+ #### Option A: LLM Proxy (recommended — strongest protection)
131
202
 
132
- ### 1. Configure upstream MCP servers
133
-
134
- In your OpenClaw config, add the servers you want Carapace to manage:
135
-
136
- ```json5
137
- {
138
- plugins: {
139
- entries: {
140
- "carapace": {
141
- enabled: true,
142
- config: {
143
- guiPort: 19820,
144
- defaultPolicy: "allow-all",
145
- servers: {
146
- "filesystem": {
147
- transport: "stdio",
148
- command: "npx",
149
- args: ["-y", "@modelcontextprotocol/server-filesystem", "/home/user/docs"]
150
- },
151
- "github": {
152
- transport: "stdio",
153
- command: "npx",
154
- args: ["-y", "@modelcontextprotocol/server-github"],
155
- env: { "GITHUB_TOKEN": "${GITHUB_TOKEN}" }
156
- }
157
- }
158
- }
159
- }
160
- }
161
- }
162
- }
163
- ```
203
+ The proxy sits between your agent and the AI model. It holds the real API key, intercepts every tool call in the AI's response, and removes anything your policies don't allow. **The agent can't bypass this because it never has the real API key.**
204
+
205
+ Add these sections to your `~/.openclaw/openclaw.json`:
206
+
207
+ **1. Add the Carapace plugin** (under `plugins.entries`):
164
208
 
165
- ### 2. Enable the LLM Proxy (recommended)
166
-
167
- The LLM Proxy is the strongest enforcement mode. Carapace holds the real API key and intercepts tool calls before OpenClaw can execute them.
168
-
169
- ```json5
170
- {
171
- plugins: {
172
- entries: {
173
- carapace: {
174
- enabled: true,
175
- config: {
176
- proxy: {
177
- enabled: true,
178
- port: 19821,
179
- upstream: {
180
- anthropic: { apiKey: "sk-ant-your-real-key-here" }
181
- }
182
- }
209
+ ```json
210
+ "carapace": {
211
+ "enabled": true,
212
+ "config": {
213
+ "guiPort": 19820,
214
+ "defaultPolicy": "allow-all",
215
+ "proxy": {
216
+ "enabled": true,
217
+ "port": 19821,
218
+ "upstream": {
219
+ "anthropic": {
220
+ "apiKey": "sk-ant-your-real-api-key-here"
183
221
  }
184
222
  }
185
- }
186
- },
187
- // Point OpenClaw at the proxy instead of the real API
188
- providers: {
189
- anthropic: {
190
- apiKey: "carapace-proxy", // dummy — proxy holds the real key
191
- baseUrl: "http://127.0.0.1:19821"
223
+ },
224
+ "servers": {
225
+ "filesystem": {
226
+ "transport": "stdio",
227
+ "command": "npx",
228
+ "args": ["-y", "@modelcontextprotocol/server-filesystem", "/home/user/docs"]
229
+ }
192
230
  }
193
231
  }
194
232
  }
195
233
  ```
196
234
 
197
- Now every tool call the LLM suggests goes through Cedar. If Cedar denies it, the tool call is stripped from the response before OpenClaw ever sees it.
198
-
199
- ### 3. (Alternative) Close the bypass gap without the proxy
235
+ For **OpenAI** models, use `"openai"` instead of `"anthropic"` in the upstream block.
200
236
 
201
- By default, agents can still use OpenClaw's built-in `exec` and `web_fetch` tools, which bypass Cedar entirely. Run setup to close this:
237
+ **2. Run setup:**
202
238
 
203
239
  ```bash
204
240
  openclaw carapace setup
241
+ openclaw gateway restart
205
242
  ```
206
243
 
207
- This adds `exec`, `web_fetch`, and `web_search` to `tools.deny` in your OpenClaw config, forcing agents to use `carapace_exec` and `carapace_fetch` instead — which go through Cedar.
244
+ This automatically:
245
+ - Points your LLM provider at the Carapace proxy (sets `models.providers.<provider>.baseUrl`)
246
+ - Denies built-in tools that would bypass Cedar (`exec`, `web_fetch`, `web_search`)
208
247
 
209
- You can check for bypasses anytime:
248
+ Your existing API key environment variable (`ANTHROPIC_API_KEY` / `OPENAI_API_KEY`) still works — the proxy replaces the auth header when forwarding. You don't need to move any keys around.
249
+
250
+ **3. Verify:**
210
251
 
211
252
  ```bash
253
+ curl http://127.0.0.1:19821/health
254
+ # Should return: {"ok":true,"stats":{"requests":0,...}}
255
+
212
256
  openclaw carapace check
257
+ # Should return: ✅ No bypass vulnerabilities found.
213
258
  ```
214
259
 
215
- > ⚠️ **Without this step, Carapace policies are advisory, not enforced.** The agent can simply choose to use the built-in tools instead. Always run `carapace setup` for real security.
216
-
217
- ### 4. Open the control GUI
218
-
219
- Navigate to [http://localhost:19820](http://localhost:19820) in your browser. You'll see all discovered tools from all connected servers.
220
-
221
- ### 5. Enable tools
222
-
223
- Toggle individual tools on/off. Each toggle writes a Cedar policy:
260
+ #### Option B: Tool-level gating (without proxy)
224
261
 
225
- - **Toggle ON** creates a `permit` policy for that tool
226
- - **Toggle OFF** → creates a `forbid` policy for that tool
262
+ If you don't want to proxy LLM traffic, just omit the `proxy` section from the config above. Then run:
227
263
 
228
- ### 6. Create custom policies
264
+ ```bash
265
+ openclaw carapace setup
266
+ openclaw gateway restart
267
+ ```
229
268
 
230
- Click **"+ New Policy"** to open the visual builder, or edit policies directly in the Policies tab. Examples:
269
+ This denies built-in tools (`exec`, `web_fetch`, `web_search`) so the agent must use Carapace's Cedar-gated versions instead.
231
270
 
232
- ```cedar
233
- // Allow the agent to read files but not write them
234
- permit(
235
- principal is Jans::Workload,
236
- action == Jans::Action::"call_tool",
237
- resource == Jans::Tool::"filesystem/read_file"
238
- );
271
+ > ⚠️ **Without the proxy, this relies on the agent using the right tools.** The proxy (Option A) is stronger because it's un-bypassable.
239
272
 
240
- // Block all write operations across all servers
241
- forbid(
242
- principal,
243
- action == Jans::Action::"call_tool",
244
- resource == Jans::Tool::"filesystem/write_file"
245
- );
273
+ ### Step 3: Open the dashboard
246
274
 
247
- // Allow git and npm commands, block everything else
248
- permit(
249
- principal is Jans::Workload,
250
- action == Jans::Action::"exec_command",
251
- resource == Jans::Shell::"git"
252
- );
253
- permit(
254
- principal is Jans::Workload,
255
- action == Jans::Action::"exec_command",
256
- resource == Jans::Shell::"npm"
257
- );
275
+ Go to [http://localhost:19820](http://localhost:19820) to see your tools, manage policies, and control access.
258
276
 
259
- // Allow API calls to GitHub, block all other domains
260
- permit(
261
- principal is Jans::Workload,
262
- action == Jans::Action::"call_api",
263
- resource == Jans::API::"api.github.com"
264
- );
277
+ ### Uninstalling
265
278
 
266
- // Block a specific domain
267
- forbid(
268
- principal,
269
- action == Jans::Action::"call_api",
270
- resource == Jans::API::"evil.example.com"
271
- );
279
+ Carapace modifies your OpenClaw config during setup (denying built-in tools, adding proxy baseUrl overrides). The uninstall command reverses all of it:
272
280
 
273
- // Allow everything (use with caution)
274
- permit(
275
- principal is Jans::Workload,
276
- action,
277
- resource
278
- );
281
+ ```bash
282
+ openclaw carapace uninstall
283
+ openclaw gateway restart
279
284
  ```
280
285
 
281
- > 📖 **Want more?** See [Recommended Policies](docs/RECOMMENDED-POLICIES.md) for real-world policies covering destructive commands, credential theft, data exfiltration, email deletion, and complete starter configurations.
286
+ This will:
287
+ - Restore the built-in `exec`, `web_fetch`, and `web_search` tools (removes them from `tools.deny`)
288
+ - Remove the proxy baseUrl override so your provider connects directly to its API again
289
+ - Disable the Carapace plugin in config
282
290
 
283
- ### 7. Verify policies
291
+ To fully remove the plugin files:
284
292
 
285
- Click **⚡ Verify** to validate that all policies are syntactically correct and consistent.
293
+ ```bash
294
+ rm -rf ~/.openclaw/extensions/carapace
295
+ ```
286
296
 
287
- ## How It Works
297
+ ### For development
288
298
 
289
- ### Cedar Policy Evaluation
299
+ ```bash
300
+ git clone https://github.com/clawdreyhepburn/carapace.git
301
+ cd carapace
302
+ npm install
303
+ npx tsx test/harness.ts # Starts test servers + GUI on port 19820
304
+ ```
290
305
 
291
- Carapace uses [Cedarling](https://github.com/JanssenProject/jans/tree/main/jans-cedarling), Gluu's high-performance Cedar policy engine compiled to WebAssembly. This means:
306
+ ---
292
307
 
293
- - **Real Cedar evaluation** — not a simplified subset. Full Cedar 4.4.2 with the official Rust SDK.
294
- - **Three resource types** — `Tool` (MCP tools), `Shell` (commands by binary name), `API` (outbound HTTP by domain). All go through the same Cedar engine.
295
- - **Forbid always wins** — if any policy says `forbid`, the request is denied regardless of any `permit` policies. This is core Cedar semantics and prevents privilege escalation.
296
- - **Allow-all by default** — installing Carapace doesn't break anything. All operations work until you add `forbid` policies. Switch to `deny-all` when you're ready for least-privilege.
297
- - **Sub-millisecond evaluation** — WASM runs at near-native speed. Typical authorization decisions take <6ms.
308
+ ## Quick Start
298
309
 
299
- ### Resource Types
310
+ Once you've installed and configured Carapace (see [Installation](#installation) above), here's how to start using it.
300
311
 
301
- | Type | Cedar Entity | Action | Gates | Example |
302
- |------|-------------|--------|-------|---------|
303
- | MCP Tool | `Jans::Tool` | `call_tool` | Upstream MCP server calls | `Tool::"filesystem/write_file"` |
304
- | Shell | `Jans::Shell` | `exec_command` | Local command execution | `Shell::"rm"`, `Shell::"git"` |
305
- | API | `Jans::API` | `call_api` | Outbound HTTP requests | `API::"api.github.com"` |
312
+ ### Write your first policy
306
313
 
307
- Shell commands are matched by **binary name** (the first token of the command). API calls are matched by **domain name**. This keeps policies readable and auditable — you can see at a glance "this agent can run `git` and `npm` but not `rm` or `curl`."
314
+ Here's a common starting point let the agent use development tools but block dangerous commands:
308
315
 
309
- ### Policy Store Format
316
+ ```cedar
317
+ // Allow git, ls, cat, grep
318
+ permit(principal is Jans::Workload, action == Jans::Action::"exec_command", resource == Jans::Shell::"git");
319
+ permit(principal is Jans::Workload, action == Jans::Action::"exec_command", resource == Jans::Shell::"ls");
320
+ permit(principal is Jans::Workload, action == Jans::Action::"exec_command", resource == Jans::Shell::"cat");
321
+ permit(principal is Jans::Workload, action == Jans::Action::"exec_command", resource == Jans::Shell::"grep");
322
+
323
+ // Block dangerous commands
324
+ forbid(principal, action == Jans::Action::"exec_command", resource == Jans::Shell::"rm");
325
+ forbid(principal, action == Jans::Action::"exec_command", resource == Jans::Shell::"sudo");
326
+
327
+ // Allow GitHub API, block data exfiltration sites
328
+ permit(principal is Jans::Workload, action == Jans::Action::"call_api", resource == Jans::API::"api.github.com");
329
+ forbid(principal, action == Jans::Action::"call_api", resource == Jans::API::"pastebin.com");
330
+ ```
310
331
 
311
- Policies are stored as individual `.cedar` files in the policy directory (default: `~/.openclaw/mcp-policies/`). On startup and after any change, Carapace builds a [Cedarling Policy Store](https://github.com/JanssenProject/jans/wiki/Cedarling-Nativity-Plan) — a portable JSON bundle containing all policies, the Cedar schema, and trusted issuer configuration.
332
+ > 🔒 **Want the full security walkthrough?** See the [Security Hardening Guide](docs/SECURITY.md) — step-by-step instructions with copy-paste commands for macOS, Linux, and Windows.
333
+ >
334
+ > 📖 **Want more policy examples?** See [Recommended Policies](docs/RECOMMENDED-POLICIES.md) — ready-made policies for common scenarios like blocking credential access, preventing data exfiltration, and complete starter configurations for different agent roles.
312
335
 
313
- ### Tool Categorization
336
+ ---
314
337
 
315
- Tools are automatically categorized by operation type based on name analysis:
338
+ ## Design Philosophy
316
339
 
317
- | Category | Color | Risk | Examples |
318
- |----------|-------|------|----------|
319
- | ✏️ Write | Orange | High | `write_file`, `edit_file`, `create_directory` |
320
- | ⚡ Execute | Red | High | `toggle-logging`, `trigger-long-running-operation` |
321
- | 🔍 Browse | Blue | Medium | `list_directory`, `search_files`, `get-env` |
322
- | 📖 Read | Teal | Low | `read_file`, `echo`, `get-sum` |
340
+ **Installing Carapace should never break your agent.** The default is `allow-all` — everything works exactly as before. You get visibility first (see what tools exist, what's being called) and control second (add restrictions when you're ready).
323
341
 
324
- The default sort order puts Write and Execute tools at the top — the tools that need human review first.
342
+ The recommended progression:
325
343
 
326
- ### API Endpoints
344
+ 1. **Install** → everything works, open the GUI and look around
345
+ 2. **Observe** → see what tools your agent actually uses
346
+ 3. **Forbid the scary stuff** → block `rm`, `sudo`, exfiltration domains
347
+ 4. **Lock down** → switch to `deny-all` and explicitly permit only what's needed
327
348
 
328
- The GUI communicates with Carapace through a local REST API:
349
+ Most people should stay at step 3. Step 4 is for when you really understand your agent's tool surface.
329
350
 
330
- | Endpoint | Method | Description |
331
- |----------|--------|-------------|
332
- | `/api/status` | GET | Server status, all tools, all policies |
333
- | `/api/tools` | GET | List tools (optional `?server=` filter) |
334
- | `/api/toggle` | POST | Enable/disable a resource `{"tool": "...", "enabled": true, "type": "tool\|shell\|api"}` |
335
- | `/api/policy` | POST | Create/update a policy `{"id": "...", "raw": "..."}` |
336
- | `/api/policy` | DELETE | Delete a policy `{"id": "..."}` |
337
- | `/api/policies` | GET | List all policies |
338
- | `/api/schema` | GET | Get Cedar schema (parsed + raw) |
339
- | `/api/schema` | POST | Update Cedar schema `{"raw": "..."}` |
340
- | `/api/verify` | POST | Verify all policies |
351
+ ---
341
352
 
342
353
  ## Security
343
354
 
344
- ### Threat Model
345
-
346
- Carapace is designed to protect against:
347
-
348
- 1. **Overprivileged agents** — An agent configured with access to 50 MCP tools but only needing 5. Start with allow-all (safe install), then use the GUI to lock down what you don't need. Switch to `deny-all` for full least-privilege.
349
-
350
- 2. **Privilege escalation via tool chaining** — An agent using a permitted tool to accomplish what a forbidden tool would do. Cedar's `forbid`-always-wins semantics help here: you can blanket-permit and then surgically forbid dangerous operations.
351
-
352
- 3. **Configuration drift** — Tool permissions accumulating over time without review. The GUI provides a single view of all permissions, and policies are stored as auditable files.
353
-
354
- ### What Carapace Does NOT Protect Against
355
+ ### What Carapace protects against
355
356
 
356
- - **Malicious MCP servers** — Carapace trusts the upstream MCP servers to behave as described. It does not sandbox server execution.
357
- - **Argument-level validation** — Carapace authorizes *which* operation can be performed (which tool, which binary, which domain), not the specific arguments. Cedar conditions can add argument-level checks, but this requires custom policies.
358
- - **Shell argument injection** — Carapace gates by binary name (`git`, `npm`), not by the full command line. An agent permitted to run `git` could run `git push --force`. Use Cedar `when` conditions on `context.args` for finer control.
359
- - **Network-level attacks** — The GUI runs on localhost without authentication. See [GUI Security](#gui-security) below.
357
+ - **Overprivileged agents** — Your agent has access to 50 tools but only needs 5. Carapace lets you restrict the other 45.
358
+ - **Prompt injection** — Someone tricks your agent into running dangerous commands. If the policy says `rm` is forbidden, it doesn't matter what the prompt says.
359
+ - **Data exfiltration** — Your agent tries to send sensitive data to an external service. If the domain isn't permitted, the request is blocked.
360
+ - **Privilege escalation** — An agent tries to use one permitted tool to accomplish what a forbidden tool would do. Cedar's forbid-always-wins makes this harder.
360
361
 
361
- ### GUI Security
362
+ ### What Carapace does NOT protect against
362
363
 
363
- The control GUI binds to `127.0.0.1` (localhost only) by default. It is **not** accessible from the network.
364
+ - **Malicious MCP servers** Carapace trusts the MCP servers themselves. If a server lies about what a tool does, Carapace can't detect that.
365
+ - **Argument-level abuse** — Carapace checks *which* command runs (e.g., `git`), not *how* it's used (e.g., `git push --force`). You can add argument-level checks with Cedar `when` conditions, but it's not automatic.
366
+ - **Permitted binary abuse** — If you permit `node`, the agent can run `node -e "require('child_process').execSync('rm -rf /')"`. Permitting a language runtime is effectively permitting everything. See [Dangerous Permits](docs/SECURITY.md#dangerous-permits).
367
+ - **Code that runs outside the LLM** — OpenClaw hooks and plugins run directly in the process, not through the AI model. Carapace can't gate those. See [Enforcement Coverage](docs/SECURITY.md#enforcement-coverage).
364
368
 
365
- > ⚠️ **Do not expose the GUI port to the network.** The API has no authentication. Anyone who can reach the API can modify policies.
369
+ ### GUI security
366
370
 
367
- If you need remote access, put it behind an authenticated reverse proxy (e.g., Caddy with basic auth, or an SSH tunnel).
371
+ The dashboard runs on `localhost` only it's not accessible from the network. There's no authentication on the API. **Do not expose port 19820 to the internet.** If you need remote access, use an SSH tunnel or an authenticated reverse proxy.
368
372
 
369
- ### Policy File Security
370
-
371
- Policy files are stored in `~/.openclaw/mcp-policies/` by default. Ensure this directory has appropriate file permissions:
372
-
373
- ```bash
374
- chmod 700 ~/.openclaw/mcp-policies/
375
- ```
376
-
377
- ### Cedar Schema Trust
378
-
379
- The Cedar schema defines what entity types and actions exist. A modified schema could allow policies to be written that appear restrictive but are actually permissive due to type mismatches. Treat the schema file with the same care as the policies themselves.
373
+ ---
380
374
 
381
375
  ## Configuration Reference
382
376
 
377
+ ### Plugin config
378
+
383
379
  | Property | Type | Default | Description |
384
380
  |----------|------|---------|-------------|
385
- | `guiPort` | number | `19820` | Port for the local control GUI |
386
- | `servers` | object | `{}` | Upstream MCP servers (see [Quick Start](#quick-start)) |
387
- | `policyDir` | string | `~/.openclaw/mcp-policies/` | Directory for Cedar policy files |
388
- | `defaultPolicy` | `"deny-all"` \| `"allow-all"` | `"allow-all"` | Default policy for tools. `allow-all` keeps everything working on install — use the GUI to restrict. `deny-all` requires explicit permits. |
389
- | `verify` | boolean | `false` | Run verification on policy changes |
390
-
391
- ### Server Configuration
392
-
393
- Each server entry supports:
381
+ | `guiPort` | number | `19820` | Port for the control dashboard |
382
+ | `servers` | object | `{}` | MCP servers to connect to (see Quick Start) |
383
+ | `policyDir` | string | `~/.openclaw/mcp-policies/` | Where Cedar policy files are stored |
384
+ | `defaultPolicy` | `"allow-all"` or `"deny-all"` | `"allow-all"` | Starting posture. `allow-all` is safe to install — nothing breaks. `deny-all` requires explicit permits for every tool. |
385
+ | `verify` | boolean | `false` | Validate policies on every change |
386
+ | `proxy.enabled` | boolean | `false` | Enable the LLM proxy |
387
+ | `proxy.port` | number | `19821` | Port for the LLM proxy |
388
+ | `proxy.upstream.anthropic.apiKey` | string | — | Your real Anthropic API key |
389
+ | `proxy.upstream.anthropic.url` | string | `https://api.anthropic.com` | Anthropic API base URL |
390
+ | `proxy.upstream.openai.apiKey` | string | — | Your real OpenAI API key |
391
+ | `proxy.upstream.openai.url` | string | `https://api.openai.com` | OpenAI API base URL |
392
+
393
+ ### MCP server config
394
394
 
395
395
  | Property | Type | Description |
396
396
  |----------|------|-------------|
397
- | `transport` | `"stdio"` \| `"http"` \| `"sse"` | Transport protocol (stdio supported in v0.1) |
398
- | `command` | string | Command to run (stdio transport) |
399
- | `args` | string[] | Command arguments |
397
+ | `transport` | `"stdio"` | How to connect (stdio is currently supported) |
398
+ | `command` | string | Program to run |
399
+ | `args` | string[] | Command-line arguments |
400
400
  | `env` | object | Environment variables |
401
- | `url` | string | Server URL (http/sse transport) |
401
+
402
+ ### CLI commands
403
+
404
+ ```bash
405
+ openclaw carapace setup # Configure OpenClaw (proxy baseUrl + deny bypass tools)
406
+ openclaw carapace check # Check for bypass vulnerabilities
407
+ openclaw carapace status # Show connected servers, tool counts, proxy status
408
+ openclaw carapace tools # List all tools with enabled/disabled status
409
+ openclaw carapace verify # Validate all policies
410
+ openclaw carapace uninstall # Reverse all config changes, restore built-in tools
411
+ ```
412
+
413
+ ---
402
414
 
403
415
  ## Development
404
416
 
@@ -407,87 +419,97 @@ git clone https://github.com/clawdreyhepburn/carapace.git
407
419
  cd carapace
408
420
  npm install
409
421
 
410
- # Run the test harness (starts 2 MCP servers + GUI)
422
+ # Run the test harness (2 MCP servers + GUI on port 19820)
411
423
  npx tsx test/harness.ts
412
424
 
413
425
  # Type check
414
426
  npx tsc --noEmit
415
427
 
416
- # Run tests
417
- npm test
428
+ # Run the full test suite
429
+ npx tsx test/test-shell-gate.mjs # Shell gating (9 tests)
430
+ npx tsx test/test-llm-proxy.mjs # LLM proxy filtering (10 tests)
431
+ npx tsx test/test-adversarial.mjs # Adversarial bypass attempts (30+9 tests)
432
+ npx tsx test/test-block-myself.mjs # End-to-end cp block demo
418
433
  ```
419
434
 
420
- ### Project Structure
435
+ ### Project structure
421
436
 
422
437
  ```
423
438
  carapace/
424
439
  ├── src/
425
- │ ├── index.ts # OpenClaw plugin entry point
426
- │ ├── cedar-engine-cedarling.ts # Cedarling WASM integration
427
- │ ├── cedar-engine.ts # Fallback Cedar engine (no WASM)
428
- │ ├── mcp-aggregator.ts # MCP server connection & tool discovery
440
+ │ ├── index.ts # OpenClaw plugin entry — registers tools, services, CLI
441
+ │ ├── llm-proxy.ts # LLM proxy — intercepts tool calls in AI responses
442
+ │ ├── cedar-engine-cedarling.ts # Cedarling WASM engine real Cedar 4.4.2 evaluation
443
+ │ ├── cedar-engine.ts # Fallback engine (string matching, no WASM needed)
444
+ │ ├── mcp-aggregator.ts # Connects to MCP servers, discovers tools, proxies calls
429
445
  │ ├── types.ts # Shared TypeScript types
430
446
  │ └── gui/
431
- │ ├── server.ts # HTTP server for the control GUI
432
- │ └── html.ts # Single-file GUI (HTML + CSS + JS)
447
+ │ ├── server.ts # HTTP server for the dashboard
448
+ │ └── html.ts # Dashboard UI (single HTML file, no build step)
433
449
  ├── test/
434
- └── harness.ts # Standalone test harness
435
- ├── policies/ # Default policy directory
450
+ ├── harness.ts # Standalone test environment
451
+ ├── test-shell-gate.mjs # Shell command authorization tests
452
+ │ ├── test-llm-proxy.mjs # LLM proxy interception tests
453
+ │ ├── test-adversarial.mjs # Adversarial bypass test suite
454
+ │ └── test-block-myself.mjs # End-to-end demo: block cp, try to copy, get denied
436
455
  ├── docs/
437
- └── screenshots/ # GUI screenshots
456
+ ├── SECURITY.md # Security hardening (macOS/Linux/Windows)
457
+ │ ├── RECOMMENDED-POLICIES.md # Policy examples for common use cases
458
+ │ └── screenshots/ # Dashboard screenshots
438
459
  ├── LICENSE # Apache-2.0
439
- ├── NOTICE # Attribution and trademark notice
440
- └── package.json
460
+ ├── NOTICE # Trademark notice
461
+ └── openclaw.plugin.json # OpenClaw plugin manifest
441
462
  ```
442
463
 
464
+ ---
465
+
443
466
  ## Learn More
444
467
 
445
- Want to understand the ideas behind Carapace? Check out the **Cedar for AI Agents** blog series:
468
+ ### Cedar for AI Agents blog series
469
+
470
+ The ideas behind Carapace, explained step by step:
446
471
 
447
- 1. [Part 1: Why Your AI Agent Needs a Policy Language](https://clawdrey.com/blog/cedar-for-ai-agents-part-1-why-your-ai-agent-needs-a-policy-language.html)
448
- 2. [Part 2: Writing Your First Agent Policy](https://clawdrey.com/blog/cedar-for-ai-agents-part-2-writing-your-first-agent-policy.html)
449
- 3. [Part 3: When Forbid Meets Permit](https://clawdrey.com/blog/cedar-for-ai-agents-part-3-when-forbid-meets-permit.html)
450
- 4. [Part 4: Proving It SMT Solvers and Why I Trust Math More Than Tests](https://clawdrey.com/blog/proving-it-smt-solvers-and-why-i-trust-math-more-than-tests.html)
472
+ 1. [Why Your AI Agent Needs a Policy Language](https://clawdrey.com/blog/cedar-for-ai-agents-part-1-why-your-ai-agent-needs-a-policy-language.html) — why config files aren't enough
473
+ 2. [Writing Your First Agent Policy](https://clawdrey.com/blog/cedar-for-ai-agents-part-2-writing-your-first-agent-policy.html) — modeling agents, tools, and actions in Cedar
474
+ 3. [When Forbid Meets Permit](https://clawdrey.com/blog/cedar-for-ai-agents-part-3-when-forbid-meets-permit.html) — why "forbid always wins" matters for safety
475
+ 4. [Proving It: SMT Solvers and Why I Trust Math More Than Tests](https://clawdrey.com/blog/proving-it-smt-solvers-and-why-i-trust-math-more-than-tests.html) — formally verifying that policies are correct
451
476
 
452
- More writing, projects, and general lobster antics at [clawdrey.com](https://clawdrey.com).
477
+ More at [clawdrey.com](https://clawdrey.com).
453
478
 
454
- ## Built With
479
+ ### Built with
455
480
 
456
- - **[Cedar](https://www.cedarpolicy.com/)** — Policy language by AWS. Declarative, analyzable, fast.
457
- - **[Cedarling](https://github.com/JanssenProject/jans/tree/main/jans-cedarling)** — Cedar policy engine by [Gluu](https://gluu.org/), compiled to WebAssembly. Provides JWT-aware authorization and the Policy Store format.
458
- - **[MCP (Model Context Protocol)](https://modelcontextprotocol.io/)** — Open protocol for connecting AI agents to tools and data sources.
459
- - **[OpenClaw](https://github.com/openclaw/openclaw)** — Open-source AI agent runtime.
481
+ - **[Cedar](https://www.cedarpolicy.com/)** — Policy language by AWS. Human-readable rules with formal guarantees.
482
+ - **[Cedarling](https://github.com/JanssenProject/jans/tree/main/jans-cedarling)** — Cedar engine by [Gluu](https://gluu.org/), compiled to WebAssembly for speed.
483
+ - **[MCP](https://modelcontextprotocol.io/)** — Open protocol for connecting AI agents to tools.
484
+ - **[OpenClaw](https://github.com/openclaw/openclaw)** — Open-source AI agent platform.
485
+
486
+ ---
460
487
 
461
488
  ## Contributors
462
489
 
463
- <!-- ALL-CONTRIBUTORS-LIST:START -->
464
490
  | Avatar | Name | Role |
465
491
  |--------|------|------|
466
- | <img src="https://github.com/ClawdreyHepworthy.png" width="50"> | **Clawdrey Hepburn** ([@ClawdreyHepburn](https://x.com/ClawdreyHepburn)) | Creator, primary author |
492
+ | <img src="https://github.com/ClawdreyHepburn.png" width="50"> | **Clawdrey Hepburn** ([@ClawdreyHepburn](https://x.com/ClawdreyHepburn)) | Creator, primary author |
467
493
  | <img src="https://github.com/Sarahcec.png" width="50"> | **Sarah Cecchetti** ([@Sarahcec](https://github.com/Sarahcec)) | Co-creator, product direction |
468
494
  | <img src="https://github.com/nynymike.png" width="50"> | **Michael Schwartz** ([@nynymike](https://github.com/nynymike)) | Cedarling / Gluu |
469
- <!-- ALL-CONTRIBUTORS-LIST:END -->
470
-
471
- ## License
472
-
473
- Copyright 2026 Clawdrey Hepburn LLC. All rights reserved.
474
495
 
475
- Licensed under the Apache License, Version 2.0. See [LICENSE](LICENSE) for the full text.
496
+ ---
476
497
 
477
- **"Carapace"** is a trademark of Clawdrey Hepburn LLC. See [NOTICE](NOTICE) for trademark details.
498
+ ## License
478
499
 
479
- ## Attribution & Usage Guidelines
500
+ Copyright 2026 Clawdrey Hepburn LLC. Licensed under [Apache-2.0](LICENSE).
480
501
 
481
- We'd love for you to tell people you use Carapace! Here's how to reference it correctly:
502
+ **"Carapace"** is a trademark of Clawdrey Hepburn LLC. See [NOTICE](NOTICE).
482
503
 
483
- ### ✅ Correct Usage
504
+ ### Attribution
484
505
 
485
- - "**Protected by Carapace**" great for badges and footers
486
- - "**Powered by Carapace**" — great for technical documentation
487
- - "**Built with Carapace**" — great for project READMEs
488
- - "**Uses Carapace for MCP tool authorization**" — great for blog posts
506
+ Using Carapace? Here's how to reference it:
489
507
 
490
- ### Badge
508
+ - ✅ "**Protected by Carapace**" — for badges and footers
509
+ - ✅ "**Powered by Carapace**" — for technical docs
510
+ - ✅ "**Built with Carapace**" — for project READMEs
511
+ - ❌ ~~"Made by Carapace"~~ — implies we're liable for what your agent does
512
+ - ❌ ~~"Certified by Carapace"~~ — we don't certify anything
491
513
 
492
514
  ```markdown
493
515
  ![Protected by Carapace](https://img.shields.io/badge/protected%20by-Carapace%20🦞-teal)
@@ -495,18 +517,12 @@ We'd love for you to tell people you use Carapace! Here's how to reference it co
495
517
 
496
518
  ![Protected by Carapace](https://img.shields.io/badge/protected%20by-Carapace%20🦞-teal)
497
519
 
498
- ### Incorrect Usage
499
-
500
- - ~~"**Made by Carapace**"~~ — Carapace is a policy engine, not a manufacturer. This implies liability on our part for what your agent does.
501
- - ~~"**Certified by Carapace**"~~ — We don't certify anything. Carapace enforces policies you write.
502
- - ~~"**Carapace-approved**"~~ — Same issue. The policies are yours; the enforcement is ours.
503
-
504
- **The distinction matters:** Carapace enforces *your* policies. You are responsible for writing good policies. We are responsible for evaluating them correctly.
520
+ **You write the policies. We enforce them.**
505
521
 
506
522
  ---
507
523
 
508
524
  <p align="center">
509
- <em>A carapace is the hard upper shell of a crustacean — an immutable boundary that defines the limits of the creature inside. It protects, it constrains, it's structural.</em>
525
+ <em>A carapace is the hard upper shell of a crustacean — an immutable boundary that protects the creature inside.</em>
510
526
  </p>
511
527
  <p align="center">
512
528
  <strong>Your agent's exoskeleton.</strong>