@anthropic-ai/sandbox-runtime 0.0.1 → 0.0.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.
Files changed (52) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +173 -88
  3. package/dist/cli.js +72 -7
  4. package/dist/cli.js.map +1 -1
  5. package/dist/index.d.ts +6 -1
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +5 -0
  8. package/dist/index.js.map +1 -1
  9. package/dist/sandbox/generate-seccomp-filter.d.ts +64 -0
  10. package/dist/sandbox/generate-seccomp-filter.d.ts.map +1 -0
  11. package/dist/sandbox/generate-seccomp-filter.js +447 -0
  12. package/dist/sandbox/generate-seccomp-filter.js.map +1 -0
  13. package/dist/sandbox/linux-sandbox-utils.d.ts +49 -3
  14. package/dist/sandbox/linux-sandbox-utils.d.ts.map +1 -1
  15. package/dist/sandbox/linux-sandbox-utils.js +247 -84
  16. package/dist/sandbox/linux-sandbox-utils.js.map +1 -1
  17. package/dist/sandbox/macos-sandbox-utils.d.ts +3 -1
  18. package/dist/sandbox/macos-sandbox-utils.d.ts.map +1 -1
  19. package/dist/sandbox/macos-sandbox-utils.js +12 -22
  20. package/dist/sandbox/macos-sandbox-utils.js.map +1 -1
  21. package/dist/sandbox/sandbox-config.d.ts +122 -0
  22. package/dist/sandbox/sandbox-config.d.ts.map +1 -0
  23. package/dist/sandbox/sandbox-config.js +75 -0
  24. package/dist/sandbox/sandbox-config.js.map +1 -0
  25. package/dist/sandbox/sandbox-manager.d.ts +3 -3
  26. package/dist/sandbox/sandbox-manager.d.ts.map +1 -1
  27. package/dist/sandbox/sandbox-manager.js +143 -236
  28. package/dist/sandbox/sandbox-manager.js.map +1 -1
  29. package/dist/sandbox/sandbox-schemas.d.ts +0 -76
  30. package/dist/sandbox/sandbox-schemas.d.ts.map +1 -1
  31. package/dist/sandbox/sandbox-schemas.js +1 -230
  32. package/dist/sandbox/sandbox-schemas.js.map +1 -1
  33. package/dist/sandbox/sandbox-utils.d.ts.map +1 -1
  34. package/dist/sandbox/sandbox-utils.js +5 -2
  35. package/dist/sandbox/sandbox-utils.js.map +1 -1
  36. package/dist/vendor/seccomp/arm64/unix-block.bpf +0 -0
  37. package/dist/vendor/seccomp/x64/unix-block.bpf +0 -0
  38. package/dist/vendor/seccomp-src/apply-seccomp-and-exec.py +111 -0
  39. package/dist/vendor/seccomp-src/seccomp-unix-block.c +97 -0
  40. package/package.json +10 -4
  41. package/vendor/seccomp/arm64/unix-block.bpf +0 -0
  42. package/vendor/seccomp/x64/unix-block.bpf +0 -0
  43. package/vendor/seccomp-src/apply-seccomp-and-exec.py +111 -0
  44. package/vendor/seccomp-src/seccomp-unix-block.c +97 -0
  45. package/dist/utils/exec.d.ts +0 -13
  46. package/dist/utils/exec.d.ts.map +0 -1
  47. package/dist/utils/exec.js +0 -38
  48. package/dist/utils/exec.js.map +0 -1
  49. package/dist/utils/settings.d.ts +0 -147
  50. package/dist/utils/settings.d.ts.map +0 -1
  51. package/dist/utils/settings.js +0 -244
  52. package/dist/utils/settings.js.map +0 -1
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2025 Anthropic
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -11,7 +11,7 @@ A lightweight sandboxing tool for enforcing filesystem and network restrictions
11
11
  ## Installation
12
12
 
13
13
  ```bash
14
- npm install @anthropic-ai/sandbox-runtime
14
+ npm install -g @anthropic-ai/sandbox-runtime
15
15
  ```
16
16
 
17
17
  ## Basic Usage
@@ -76,13 +76,17 @@ A key use case is sandboxing Model Context Protocol (MCP) servers to restrict th
76
76
  }
77
77
  ```
78
78
 
79
- Then configure restrictions in `~/.claude/settings.json`:
79
+ Then configure restrictions in `~/.srt-settings.json`:
80
80
  ```json
81
81
  {
82
- "permissions": {
83
- "deny": [
84
- "Edit(~/sensitive-folder)"
85
- ]
82
+ "filesystem": {
83
+ "denyRead": [],
84
+ "allowWrite": ["."],
85
+ "denyWrite": ["~/sensitive-folder"]
86
+ },
87
+ "network": {
88
+ "allowedDomains": [],
89
+ "deniedDomains": []
86
90
  }
87
91
  }
88
92
  ```
@@ -160,17 +164,30 @@ srt echo "hello world"
160
164
  srt --debug curl https://example.com
161
165
 
162
166
  # Specify custom settings file
163
- srt --settings /path/to/settings.json npm install
167
+ srt --settings /path/to/srt-settings.json npm install
164
168
  ```
165
169
 
166
170
  ### As a library
167
171
 
168
172
  ```typescript
169
- import { SandboxManager } from '@anthropic-ai/sandbox-runtime'
173
+ import { SandboxManager, type SandboxRuntimeConfig } from '@anthropic-ai/sandbox-runtime'
170
174
  import { spawn } from 'child_process'
171
175
 
176
+ // Define your sandbox configuration
177
+ const config: SandboxRuntimeConfig = {
178
+ network: {
179
+ allowedDomains: ['example.com', 'api.github.com'],
180
+ deniedDomains: []
181
+ },
182
+ filesystem: {
183
+ denyRead: ['~/.ssh'],
184
+ allowWrite: ['.', '/tmp'],
185
+ denyWrite: ['.env']
186
+ }
187
+ }
188
+
172
189
  // Initialize the sandbox (starts proxy servers, etc.)
173
- await SandboxManager.initialize()
190
+ await SandboxManager.initialize(config)
174
191
 
175
192
  // Wrap a command with sandbox restrictions
176
193
  const sandboxedCommand = await SandboxManager.wrapWithSandbox('curl https://example.com')
@@ -198,8 +215,11 @@ export { SandboxViolationStore } from '@anthropic-ai/sandbox-runtime'
198
215
 
199
216
  // TypeScript types
200
217
  export type {
201
- SandboxAskCallback,
218
+ SandboxRuntimeConfig,
219
+ NetworkConfig,
220
+ FilesystemConfig,
202
221
  IgnoreViolationsConfig,
222
+ SandboxAskCallback,
203
223
  FsReadRestrictionConfig,
204
224
  FsWriteRestrictionConfig,
205
225
  NetworkRestrictionConfig,
@@ -208,70 +228,71 @@ export type {
208
228
 
209
229
  ## Configuration
210
230
 
211
- **NOTE: Configuration format is provisional and subject to change.** The current configuration system is borrowed from Claude Code's permission model and uses Claude Code settings files. This format may evolve as the sandbox runtime matures as a standalone tool.
212
-
213
- ### Settings File Locations
231
+ ### Settings File Location
214
232
 
215
- Settings are loaded and merged in priority order from:
233
+ By default, the sandbox runtime looks for configuration at `~/.srt-settings.json`. You can specify a custom path using the `--settings` flag:
216
234
 
217
- 1. **User settings**: `~/.claude/settings.json`
218
- 2. **Project settings**: `$CWD/.claude/settings.json`
219
- 3. **Local settings**: `$CWD/.claude/settings.local.json`
220
- 4. **Policy settings**: Platform-specific managed settings
221
- - macOS: `/Library/Application Support/ClaudeCode/managed-settings.json`
222
- - Linux: `/etc/claude-code/managed-settings.json`
223
- 5. **Flag settings**: Custom path via `--settings` flag
235
+ ```bash
236
+ srt --settings /path/to/srt-settings.json <command>
237
+ ```
224
238
 
225
239
  ### Complete Configuration Example
226
240
 
227
241
  ```json
228
242
  {
229
- "sandbox": {
230
- "enabled": true,
231
- "network": {
232
- "allowUnixSockets": ["/var/run/docker.sock"],
233
- "allowLocalBinding": false,
234
- "httpProxyPort": 8888,
235
- "socksProxyPort": 1080
236
- }
243
+ "network": {
244
+ "allowedDomains": [
245
+ "github.com",
246
+ "*.github.com",
247
+ "lfs.github.com",
248
+ "api.github.com",
249
+ "npmjs.org",
250
+ "*.npmjs.org"
251
+ ],
252
+ "deniedDomains": [
253
+ "malicious.com"
254
+ ],
255
+ "allowUnixSockets": ["/var/run/docker.sock"],
256
+ "allowLocalBinding": false
237
257
  },
238
- "permissions": {
239
- "allow": [
240
- "WebFetch(domain:github.com)",
241
- "WebFetch(domain:lfs.github.com)",
242
- "WebFetch(domain:api.github.com)",
243
- "WebFetch(domain:npmjs.org)",
244
- "Edit(src/)",
245
- "Edit(test/)",
246
- "Read(.)"
258
+ "filesystem": {
259
+ "denyRead": [
260
+ "~/.ssh"
247
261
  ],
248
- "deny": [
249
- "Edit(.env)",
250
- "Edit(config/production.json)",
251
- "Read(~/.ssh)",
252
- "WebFetch(domain:malicious.com)"
262
+ "allowWrite": [
263
+ ".",
264
+ "src/",
265
+ "test/",
266
+ "/tmp"
267
+ ],
268
+ "denyWrite": [
269
+ ".env",
270
+ "config/production.json"
253
271
  ]
254
- }
272
+ },
273
+ "ignoreViolations": {
274
+ "*": ["/usr/bin", "/System"],
275
+ "git push": ["/usr/bin/nc"],
276
+ "npm": ["/private/tmp"]
277
+ },
278
+ "enableWeakerNestedSandbox": false
255
279
  }
256
280
  ```
257
281
 
258
282
  ### Configuration Options
259
283
 
260
- #### Sandbox Settings
284
+ #### Network Configuration
261
285
 
262
- - `sandbox.enabled` - Enable/disable sandboxing (boolean)
263
- - `sandbox.network.allowUnixSockets` - Unix sockets that can be accessed (array of paths)
264
- - `sandbox.network.allowLocalBinding` - Allow binding to local ports (boolean)
265
- - `sandbox.network.httpProxyPort` - Port for your own HTTP proxy (default: uses built-in proxy)
266
- - `sandbox.network.socksProxyPort` - Port for your own SOCKS5 proxy (default: uses built-in proxy)
286
+ - `network.allowedDomains` - Array of allowed domains (supports wildcards like `*.example.com`)
287
+ - `network.deniedDomains` - Array of denied domains (takes precedence over allowedDomains)
288
+ - `network.allowUnixSockets` - Array of Unix socket paths that can be accessed (macOS only)
289
+ - `network.allowLocalBinding` - Allow binding to local ports (boolean, default: false)
267
290
 
268
- #### Permission Rules
291
+ #### Filesystem Configuration
269
292
 
270
- Permission rules provide fine-grained control and use Claude Code's permission syntax:
271
-
272
- - `WebFetch(domain:example.com)` - Allow/deny network access to a domain
273
- - `Edit(path)` - Allow/deny file write access
274
- - `Read(path)` - Allow/deny file read access
293
+ - `filesystem.denyRead` - Array of paths to deny read access
294
+ - `filesystem.allowWrite` - Array of paths to allow write access (default: current working directory only)
295
+ - `filesystem.denyWrite` - Array of paths to deny write access (takes precedence over allowWrite)
275
296
 
276
297
  **Path Syntax (macOS):**
277
298
 
@@ -283,32 +304,44 @@ Paths support git-style glob patterns on macOS, similar to `.gitignore` syntax:
283
304
  - `[abc]` - Matches any character in the set (e.g., `file[0-9].txt` matches `file3.txt`)
284
305
 
285
306
  Examples:
286
- - `Edit(src/)` - Allow write to entire `src/` directory
287
- - `Edit(src/**/*.ts)` - Allow write to all `.ts` files in `src/` and subdirectories
288
- - `Read(~/.ssh)` - Deny read to SSH directory
289
- - `Edit(.env)` - Deny write to `.env` file (even if current directory is allowed)
307
+ - `"allowWrite": ["src/"]` - Allow write to entire `src/` directory
308
+ - `"allowWrite": ["src/**/*.ts"]` - Allow write to all `.ts` files in `src/` and subdirectories
309
+ - `"denyRead": ["~/.ssh"]` - Deny read to SSH directory
310
+ - `"denyWrite": [".env"]` - Deny write to `.env` file (even if current directory is allowed)
290
311
 
291
312
  **Path Syntax (Linux):**
292
313
 
293
314
  **Linux currently does not support glob matching.** Use literal paths only:
294
- - `Edit(src/)` - Allow write to `src/` directory
295
- - `Read(/home/user/.ssh)` - Deny read to SSH directory
315
+ - `"allowWrite": ["src/"]` - Allow write to `src/` directory
316
+ - `"denyRead": ["/home/user/.ssh"]` - Deny read to SSH directory
296
317
 
297
318
  **All platforms:**
298
319
  - Paths can be absolute (e.g., `/home/user/.ssh`) or relative to the current working directory (e.g., `./src`)
299
320
  - `~` expands to the user's home directory
300
321
 
322
+ #### Other Configuration
323
+
324
+ - `ignoreViolations` - Object mapping command patterns to arrays of paths where violations should be ignored
325
+ - `enableWeakerNestedSandbox` - Enable weaker sandbox mode for Docker environments (boolean, default: false)
326
+
301
327
  ### Common Configuration Recipes
302
328
 
303
329
  **Allow GitHub access** (all necessary endpoints):
304
330
  ```json
305
331
  {
306
- "permissions": {
307
- "allow": [
308
- "WebFetch(domain:github.com)",
309
- "WebFetch(domain:lfs.github.com)",
310
- "WebFetch(domain:api.github.com)"
311
- ]
332
+ "network": {
333
+ "allowedDomains": [
334
+ "github.com",
335
+ "*.github.com",
336
+ "lfs.github.com",
337
+ "api.github.com"
338
+ ],
339
+ "deniedDomains": []
340
+ },
341
+ "filesystem": {
342
+ "denyRead": [],
343
+ "allowWrite": ["."],
344
+ "denyWrite": []
312
345
  }
313
346
  }
314
347
  ```
@@ -316,17 +349,14 @@ Examples:
316
349
  **Restrict to specific directories:**
317
350
  ```json
318
351
  {
319
- "permissions": {
320
- "allow": [
321
- "Edit(src/)",
322
- "Edit(test/)",
323
- "Read(.)"
324
- ],
325
- "deny": [
326
- "Edit(.env)",
327
- "Edit(secrets/)",
328
- "Read(~/.ssh)"
329
- ]
352
+ "network": {
353
+ "allowedDomains": [],
354
+ "deniedDomains": []
355
+ },
356
+ "filesystem": {
357
+ "denyRead": ["~/.ssh"],
358
+ "allowWrite": [".", "src/", "test/"],
359
+ "denyWrite": [".env", "secrets/"]
330
360
  }
331
361
  }
332
362
  ```
@@ -357,11 +387,25 @@ Watchman accesses files outside the sandbox boundaries, which will trigger permi
357
387
  - Ubuntu/Debian: `apt-get install socat`
358
388
  - Fedora: `dnf install socat`
359
389
  - Arch: `pacman -S socat`
390
+ - **`python3` - REQUIRED for applying seccomp filters** (typically pre-installed on Linux)
391
+ - Ubuntu/Debian: `apt-get install python3`
392
+ - Fedora: `dnf install python3`
393
+ - Arch: `pacman -S python`
394
+ - **Note:** Python 3 is mandatory for Unix socket blocking security. To disable this security feature, set `allowAllUnixSockets: true` in your configuration.
360
395
  - `ripgrep` - Fast search tool for deny path detection
361
396
  - Ubuntu/Debian: `apt-get install ripgrep`
362
397
  - Fedora: `dnf install ripgrep`
363
398
  - Arch: `pacman -S ripgrep`
364
399
 
400
+ **Optional Linux dependencies (for seccomp fallback):**
401
+
402
+ The package includes pre-generated seccomp BPF filters for x86-64 and arm architectures. These dependencies are only needed if you are on a different architecture where pre-generated filters are not available:
403
+ - `gcc` or `clang` - C compiler
404
+ - `libseccomp-dev` - Seccomp library development files
405
+ - Ubuntu/Debian: `apt-get install gcc libseccomp-dev`
406
+ - Fedora: `dnf install gcc libseccomp-devel`
407
+ - Arch: `pacman -S gcc libseccomp`
408
+
365
409
  **macOS requires:**
366
410
  - `ripgrep` - Fast search tool for deny path detection
367
411
  - Install via Homebrew: `brew install ripgrep`
@@ -376,6 +420,15 @@ npm install
376
420
  # Build the project
377
421
  npm run build
378
422
 
423
+ # Build seccomp binaries (requires Docker)
424
+ npm run build:seccomp
425
+
426
+ # Run tests
427
+ npm test
428
+
429
+ # Run integration tests
430
+ npm run test:integration
431
+
379
432
  # Type checking
380
433
  npm run typecheck
381
434
 
@@ -386,6 +439,20 @@ npm run lint
386
439
  npm run format
387
440
  ```
388
441
 
442
+ ### Building Seccomp Binaries
443
+
444
+ The pre-generated BPF filters are included in the repository, but you can rebuild them if needed:
445
+
446
+ ```bash
447
+ npm run build:seccomp
448
+ ```
449
+
450
+ This script uses Docker to cross-compile seccomp binaries for multiple architectures:
451
+ - x64 (x86-64)
452
+ - arm64 (aarch64)
453
+
454
+ The script builds static generator binaries, generates the BPF filters (~104 bytes each), and stores them in `vendor/seccomp/x64/` and `vendor/seccomp/arm64/`. The generator binaries are removed to keep the package size small.
455
+
389
456
  ## Implementation Details
390
457
 
391
458
  ### Network Isolation Architecture
@@ -420,6 +487,31 @@ Filesystem restrictions are enforced at the OS level:
420
487
 
421
488
  This model lets you start with broad read access but tightly controlled write access, then refine both as needed.
422
489
 
490
+ ### Unix Socket Restrictions (Linux)
491
+
492
+ On Linux, the sandbox uses **seccomp BPF (Berkeley Packet Filter)** to block Unix domain socket creation at the syscall level. This provides an additional layer of security to prevent processes from creating new Unix domain sockets for local IPC (unless explicitly allowed).
493
+
494
+ **How it works:**
495
+
496
+ 1. **Pre-generated BPF filters**: The package includes pre-compiled BPF filters for different architectures (x64, ARM64). These are ~104 bytes each and stored in `vendor/seccomp/`. The filters are architecture-specific but libc-independent, so they work with both glibc and musl.
497
+
498
+ 2. **Runtime detection**: The sandbox automatically detects your system's architecture and loads the appropriate pre-generated BPF filter.
499
+
500
+ 3. **Syscall filtering**: The BPF filter intercepts the `socket()` syscall and blocks creation of `AF_UNIX` sockets by returning `EPERM`. This prevents sandboxed code from creating new Unix domain sockets.
501
+
502
+ 4. **Two-stage application using Python helper script**:
503
+ - Outer bwrap creates the sandbox with filesystem, network, and PID namespace restrictions
504
+ - Network bridging processes (socat) start inside the sandbox (need Unix sockets)
505
+ - Python helper script (apply-seccomp-and-exec.py) applies the seccomp filter via `prctl()`
506
+ - Python script execs the user command with seccomp active
507
+ - User command runs with all sandbox restrictions plus Unix socket creation blocking
508
+
509
+ **Security limitations**: The filter only blocks `socket(AF_UNIX, ...)` syscalls. It does not prevent operations on Unix socket file descriptors inherited from parent processes or passed via `SCM_RIGHTS`. For most sandboxing scenarios, blocking socket creation is sufficient to prevent unauthorized IPC.
510
+
511
+ **Minimal runtime dependencies**: Unlike traditional seccomp implementations that require `gcc`, `clang`, and `libseccomp-dev` at runtime, this approach bundles pre-generated BPF filters and uses a Python helper script with standard library `ctypes` to apply them via `prctl()`, eliminating compilation dependencies for end users. Requires Python 3 (typically already installed on Linux systems).
512
+
513
+ **Fallback mechanism**: If a pre-generated filter isn't available for your platform, the sandbox can fall back to runtime compilation (requires `gcc/clang` and `libseccomp-dev`).
514
+
423
515
  ### Violation Detection and Monitoring
424
516
 
425
517
  When a sandboxed process attempts to access a restricted resource:
@@ -461,17 +553,10 @@ For more sophisticated network filtering, you can configure the sandbox to use y
461
553
  ```bash
462
554
  # Start mitmproxy with custom filtering script
463
555
  mitmproxy -s custom_filter.py --listen-port 8888
464
-
465
- # Configure sandbox to use your proxy
466
- {
467
- "sandbox": {
468
- "network": {
469
- "httpProxyPort": 8888
470
- }
471
- }
472
- }
473
556
  ```
474
557
 
558
+ Note: Custom proxy configuration is not yet supported in the new configuration format. This feature will be added in a future release.
559
+
475
560
  **Important security consideration:** Even with domain allowlists, exfiltration vectors may exist. For example, allowing `github.com` lets a process push to any repository. With a custom MITM proxy and proper certificate setup, you can inspect and filter specific API calls to prevent this.
476
561
 
477
562
  ### Security Limitations