@carderne/sandbox-runtime 0.0.40

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 (83) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +684 -0
  3. package/dist/cli.d.ts +3 -0
  4. package/dist/cli.d.ts.map +1 -0
  5. package/dist/cli.js +163 -0
  6. package/dist/cli.js.map +1 -0
  7. package/dist/index.d.ts +11 -0
  8. package/dist/index.d.ts.map +1 -0
  9. package/dist/index.js +9 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/sandbox/generate-seccomp-filter.d.ts +71 -0
  12. package/dist/sandbox/generate-seccomp-filter.d.ts.map +1 -0
  13. package/dist/sandbox/generate-seccomp-filter.js +263 -0
  14. package/dist/sandbox/generate-seccomp-filter.js.map +1 -0
  15. package/dist/sandbox/http-proxy.d.ts +13 -0
  16. package/dist/sandbox/http-proxy.d.ts.map +1 -0
  17. package/dist/sandbox/http-proxy.js +217 -0
  18. package/dist/sandbox/http-proxy.js.map +1 -0
  19. package/dist/sandbox/linux-sandbox-utils.d.ts +158 -0
  20. package/dist/sandbox/linux-sandbox-utils.d.ts.map +1 -0
  21. package/dist/sandbox/linux-sandbox-utils.js +875 -0
  22. package/dist/sandbox/linux-sandbox-utils.js.map +1 -0
  23. package/dist/sandbox/macos-sandbox-utils.d.ts +40 -0
  24. package/dist/sandbox/macos-sandbox-utils.d.ts.map +1 -0
  25. package/dist/sandbox/macos-sandbox-utils.js +623 -0
  26. package/dist/sandbox/macos-sandbox-utils.js.map +1 -0
  27. package/dist/sandbox/sandbox-config.d.ts +288 -0
  28. package/dist/sandbox/sandbox-config.d.ts.map +1 -0
  29. package/dist/sandbox/sandbox-config.js +178 -0
  30. package/dist/sandbox/sandbox-config.js.map +1 -0
  31. package/dist/sandbox/sandbox-manager.d.ts +42 -0
  32. package/dist/sandbox/sandbox-manager.d.ts.map +1 -0
  33. package/dist/sandbox/sandbox-manager.js +786 -0
  34. package/dist/sandbox/sandbox-manager.js.map +1 -0
  35. package/dist/sandbox/sandbox-schemas.d.ts +57 -0
  36. package/dist/sandbox/sandbox-schemas.d.ts.map +1 -0
  37. package/dist/sandbox/sandbox-schemas.js +3 -0
  38. package/dist/sandbox/sandbox-schemas.js.map +1 -0
  39. package/dist/sandbox/sandbox-utils.d.ts +109 -0
  40. package/dist/sandbox/sandbox-utils.d.ts.map +1 -0
  41. package/dist/sandbox/sandbox-utils.js +429 -0
  42. package/dist/sandbox/sandbox-utils.js.map +1 -0
  43. package/dist/sandbox/sandbox-violation-store.d.ts +19 -0
  44. package/dist/sandbox/sandbox-violation-store.d.ts.map +1 -0
  45. package/dist/sandbox/sandbox-violation-store.js +54 -0
  46. package/dist/sandbox/sandbox-violation-store.js.map +1 -0
  47. package/dist/sandbox/socks-proxy.d.ts +13 -0
  48. package/dist/sandbox/socks-proxy.d.ts.map +1 -0
  49. package/dist/sandbox/socks-proxy.js +95 -0
  50. package/dist/sandbox/socks-proxy.js.map +1 -0
  51. package/dist/utils/config-loader.d.ts +11 -0
  52. package/dist/utils/config-loader.d.ts.map +1 -0
  53. package/dist/utils/config-loader.js +60 -0
  54. package/dist/utils/config-loader.js.map +1 -0
  55. package/dist/utils/debug.d.ts +7 -0
  56. package/dist/utils/debug.d.ts.map +1 -0
  57. package/dist/utils/debug.js +25 -0
  58. package/dist/utils/debug.js.map +1 -0
  59. package/dist/utils/platform.d.ts +15 -0
  60. package/dist/utils/platform.d.ts.map +1 -0
  61. package/dist/utils/platform.js +49 -0
  62. package/dist/utils/platform.js.map +1 -0
  63. package/dist/utils/ripgrep.d.ts +20 -0
  64. package/dist/utils/ripgrep.d.ts.map +1 -0
  65. package/dist/utils/ripgrep.js +42 -0
  66. package/dist/utils/ripgrep.js.map +1 -0
  67. package/dist/utils/which.d.ts +9 -0
  68. package/dist/utils/which.d.ts.map +1 -0
  69. package/dist/utils/which.js +25 -0
  70. package/dist/utils/which.js.map +1 -0
  71. package/dist/vendor/seccomp/arm64/apply-seccomp +0 -0
  72. package/dist/vendor/seccomp/arm64/unix-block.bpf +0 -0
  73. package/dist/vendor/seccomp/x64/apply-seccomp +0 -0
  74. package/dist/vendor/seccomp/x64/unix-block.bpf +0 -0
  75. package/dist/vendor/seccomp-src/apply-seccomp.c +98 -0
  76. package/dist/vendor/seccomp-src/seccomp-unix-block.c +97 -0
  77. package/package.json +88 -0
  78. package/vendor/seccomp/arm64/apply-seccomp +0 -0
  79. package/vendor/seccomp/arm64/unix-block.bpf +0 -0
  80. package/vendor/seccomp/x64/apply-seccomp +0 -0
  81. package/vendor/seccomp/x64/unix-block.bpf +0 -0
  82. package/vendor/seccomp-src/apply-seccomp.c +98 -0
  83. package/vendor/seccomp-src/seccomp-unix-block.c +97 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
package/dist/cli.js ADDED
@@ -0,0 +1,163 @@
1
+ #!/usr/bin/env node
2
+ import { Command } from 'commander';
3
+ import { SandboxManager } from './index.js';
4
+ import { spawn } from 'child_process';
5
+ import { logForDebugging } from './utils/debug.js';
6
+ import { loadConfig, loadConfigFromString } from './utils/config-loader.js';
7
+ import * as readline from 'readline';
8
+ import * as fs from 'fs';
9
+ import * as path from 'path';
10
+ import * as os from 'os';
11
+ /**
12
+ * Get default config path
13
+ */
14
+ function getDefaultConfigPath() {
15
+ return path.join(os.homedir(), '.srt-settings.json');
16
+ }
17
+ /**
18
+ * Create a minimal default config if no config file exists
19
+ */
20
+ function getDefaultConfig() {
21
+ return {
22
+ network: {
23
+ allowedDomains: [],
24
+ deniedDomains: [],
25
+ },
26
+ filesystem: {
27
+ denyRead: [],
28
+ allowRead: [],
29
+ allowWrite: [],
30
+ denyWrite: [],
31
+ },
32
+ };
33
+ }
34
+ async function main() {
35
+ const program = new Command();
36
+ program
37
+ .name('srt')
38
+ .description('Run commands in a sandbox with network and filesystem restrictions')
39
+ .version(process.env.npm_package_version || '1.0.0');
40
+ // Default command - run command in sandbox
41
+ program
42
+ .argument('[command...]', 'command to run in the sandbox')
43
+ .option('-d, --debug', 'enable debug logging')
44
+ .option('-s, --settings <path>', 'path to config file (default: ~/.srt-settings.json)')
45
+ .option('-c <command>', 'run command string directly (like sh -c), no escaping applied')
46
+ .option('--control-fd <fd>', 'read config updates from file descriptor (JSON lines protocol)', parseInt)
47
+ .allowUnknownOption()
48
+ .action(async (commandArgs, options) => {
49
+ try {
50
+ // Enable debug logging if requested
51
+ if (options.debug) {
52
+ process.env.DEBUG = 'true';
53
+ }
54
+ // Load config from file
55
+ const configPath = options.settings || getDefaultConfigPath();
56
+ let runtimeConfig = loadConfig(configPath);
57
+ if (!runtimeConfig) {
58
+ logForDebugging(`No config found at ${configPath}, using default config`);
59
+ runtimeConfig = getDefaultConfig();
60
+ }
61
+ // Initialize sandbox with config
62
+ logForDebugging('Initializing sandbox...');
63
+ await SandboxManager.initialize(runtimeConfig);
64
+ // Set up control fd for dynamic config updates if specified
65
+ let controlReader = null;
66
+ if (options.controlFd !== undefined) {
67
+ try {
68
+ const controlStream = fs.createReadStream('', {
69
+ fd: options.controlFd,
70
+ });
71
+ controlReader = readline.createInterface({
72
+ input: controlStream,
73
+ crlfDelay: Infinity,
74
+ });
75
+ controlReader.on('line', line => {
76
+ const newConfig = loadConfigFromString(line);
77
+ if (newConfig) {
78
+ logForDebugging(`Config updated from control fd: ${JSON.stringify(newConfig)}`);
79
+ SandboxManager.updateConfig(newConfig);
80
+ }
81
+ else if (line.trim()) {
82
+ // Only log non-empty lines that failed to parse
83
+ logForDebugging(`Invalid config on control fd (ignored): ${line}`);
84
+ }
85
+ });
86
+ controlReader.on('error', err => {
87
+ logForDebugging(`Control fd error: ${err.message}`);
88
+ });
89
+ logForDebugging(`Listening for config updates on fd ${options.controlFd}`);
90
+ }
91
+ catch (err) {
92
+ logForDebugging(`Failed to open control fd ${options.controlFd}: ${err instanceof Error ? err.message : String(err)}`);
93
+ }
94
+ }
95
+ // Cleanup control reader on exit
96
+ process.on('exit', () => {
97
+ controlReader?.close();
98
+ });
99
+ // Determine command string based on mode
100
+ let command;
101
+ if (options.c) {
102
+ // -c mode: use command string directly, no escaping
103
+ command = options.c;
104
+ logForDebugging(`Command string mode (-c): ${command}`);
105
+ }
106
+ else if (commandArgs.length > 0) {
107
+ // Default mode: simple join
108
+ command = commandArgs.join(' ');
109
+ logForDebugging(`Original command: ${command}`);
110
+ }
111
+ else {
112
+ console.error('Error: No command specified. Use -c <command> or provide command arguments.');
113
+ process.exit(1);
114
+ }
115
+ logForDebugging(JSON.stringify(SandboxManager.getNetworkRestrictionConfig(), null, 2));
116
+ // Wrap the command with sandbox restrictions
117
+ const sandboxedCommand = await SandboxManager.wrapWithSandbox(command);
118
+ // Execute the sandboxed command
119
+ const child = spawn(sandboxedCommand, {
120
+ shell: true,
121
+ stdio: 'inherit',
122
+ });
123
+ // Handle process exit
124
+ child.on('exit', (code, signal) => {
125
+ // Clean up bwrap mount point artifacts before exiting.
126
+ // On Linux, bwrap creates empty files on the host when protecting
127
+ // non-existent deny paths. This removes them.
128
+ SandboxManager.cleanupAfterCommand();
129
+ if (signal) {
130
+ if (signal === 'SIGINT' || signal === 'SIGTERM') {
131
+ process.exit(0);
132
+ }
133
+ else {
134
+ console.error(`Process killed by signal: ${signal}`);
135
+ process.exit(1);
136
+ }
137
+ }
138
+ process.exit(code ?? 0);
139
+ });
140
+ child.on('error', error => {
141
+ console.error(`Failed to execute command: ${error.message}`);
142
+ process.exit(1);
143
+ });
144
+ // Handle cleanup on interrupt
145
+ process.on('SIGINT', () => {
146
+ child.kill('SIGINT');
147
+ });
148
+ process.on('SIGTERM', () => {
149
+ child.kill('SIGTERM');
150
+ });
151
+ }
152
+ catch (error) {
153
+ console.error(`Error: ${error instanceof Error ? error.message : String(error)}`);
154
+ process.exit(1);
155
+ }
156
+ });
157
+ program.parse();
158
+ }
159
+ main().catch(error => {
160
+ console.error('Fatal error:', error);
161
+ process.exit(1);
162
+ });
163
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C,OAAO,EAAE,CAAC,CAAA;gBAC5D,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;YACjB,CAAC,CAAC,CAAA;YAEF,8BAA8B;YAC9B,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE;gBACxB,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;YACtB,CAAC,CAAC,CAAA;YAEF,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE;gBACzB,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;YACvB,CAAC,CAAC,CAAA;QACJ,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CACX,UAAU,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CACnE,CAAA;YACD,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;QACjB,CAAC;IACH,CAAC,CACF,CAAA;IAEH,OAAO,CAAC,KAAK,EAAE,CAAA;AACjB,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;IACnB,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAA;IACpC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;AACjB,CAAC,CAAC,CAAA"}
@@ -0,0 +1,11 @@
1
+ export { SandboxManager } from './sandbox/sandbox-manager.js';
2
+ export { SandboxViolationStore } from './sandbox/sandbox-violation-store.js';
3
+ export type { SandboxRuntimeConfig, NetworkConfig, FilesystemConfig, IgnoreViolationsConfig, } from './sandbox/sandbox-config.js';
4
+ export { SandboxRuntimeConfigSchema, NetworkConfigSchema, FilesystemConfigSchema, IgnoreViolationsConfigSchema, RipgrepConfigSchema, } from './sandbox/sandbox-config.js';
5
+ export type { SandboxAskCallback, FsReadRestrictionConfig, FsWriteRestrictionConfig, NetworkRestrictionConfig, NetworkHostPattern, } from './sandbox/sandbox-schemas.js';
6
+ export type { SandboxViolationEvent } from './sandbox/macos-sandbox-utils.js';
7
+ export { type SandboxDependencyCheck } from './sandbox/linux-sandbox-utils.js';
8
+ export { getDefaultWritePaths } from './sandbox/sandbox-utils.js';
9
+ export { getWslVersion } from './utils/platform.js';
10
+ export type { Platform } from './utils/platform.js';
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAC7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAA;AAG5E,YAAY,EACV,oBAAoB,EACpB,aAAa,EACb,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,6BAA6B,CAAA;AAEpC,OAAO,EACL,0BAA0B,EAC1B,mBAAmB,EACnB,sBAAsB,EACtB,4BAA4B,EAC5B,mBAAmB,GACpB,MAAM,6BAA6B,CAAA;AAGpC,YAAY,EACV,kBAAkB,EAClB,uBAAuB,EACvB,wBAAwB,EACxB,wBAAwB,EACxB,kBAAkB,GACnB,MAAM,8BAA8B,CAAA;AAGrC,YAAY,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAA;AAC7E,OAAO,EAAE,KAAK,sBAAsB,EAAE,MAAM,kCAAkC,CAAA;AAG9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAA;AAGjE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,YAAY,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ // Library exports
2
+ export { SandboxManager } from './sandbox/sandbox-manager.js';
3
+ export { SandboxViolationStore } from './sandbox/sandbox-violation-store.js';
4
+ export { SandboxRuntimeConfigSchema, NetworkConfigSchema, FilesystemConfigSchema, IgnoreViolationsConfigSchema, RipgrepConfigSchema, } from './sandbox/sandbox-config.js';
5
+ // Utility functions
6
+ export { getDefaultWritePaths } from './sandbox/sandbox-utils.js';
7
+ // Platform utilities
8
+ export { getWslVersion } from './utils/platform.js';
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kBAAkB;AAClB,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAA;AAC7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAA;AAU5E,OAAO,EACL,0BAA0B,EAC1B,mBAAmB,EACnB,sBAAsB,EACtB,4BAA4B,EAC5B,mBAAmB,GACpB,MAAM,6BAA6B,CAAA;AAepC,oBAAoB;AACpB,OAAO,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAA;AAEjE,qBAAqB;AACrB,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA"}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Get the path to a pre-generated BPF filter file from the vendor directory
3
+ * Returns the path if it exists, null otherwise
4
+ *
5
+ * Pre-generated BPF files are organized by architecture:
6
+ * - vendor/seccomp/{x64,arm64}/unix-block.bpf
7
+ *
8
+ * Tries multiple paths for resilience:
9
+ * 0. Explicit path provided via parameter (checked first if provided)
10
+ * 1. vendor/seccomp/{arch}/unix-block.bpf (bundled - when bundled into consuming packages)
11
+ * 2. ../../vendor/seccomp/{arch}/unix-block.bpf (package root - standard npm installs)
12
+ * 3. ../vendor/seccomp/{arch}/unix-block.bpf (dist/vendor - for bundlers)
13
+ * 4. Global npm install (if seccompBinaryPath not provided) - for native builds
14
+ *
15
+ * @param seccompBinaryPath - Optional explicit path to the BPF filter file. If provided and
16
+ * exists, it will be used. If not provided, falls back to searching local paths and then
17
+ * global npm install (for native builds where vendor directory isn't bundled).
18
+ */
19
+ export declare function getPreGeneratedBpfPath(seccompBinaryPath?: string): string | null;
20
+ /**
21
+ * Get the path to the apply-seccomp binary from the vendor directory
22
+ * Returns the path if it exists, null otherwise
23
+ *
24
+ * Pre-built apply-seccomp binaries are organized by architecture:
25
+ * - vendor/seccomp/{x64,arm64}/apply-seccomp
26
+ *
27
+ * Tries multiple paths for resilience:
28
+ * 0. Explicit path provided via parameter (checked first if provided)
29
+ * 1. vendor/seccomp/{arch}/apply-seccomp (bundled - when bundled into consuming packages)
30
+ * 2. ../../vendor/seccomp/{arch}/apply-seccomp (package root - standard npm installs)
31
+ * 3. ../vendor/seccomp/{arch}/apply-seccomp (dist/vendor - for bundlers)
32
+ * 4. Global npm install (if seccompBinaryPath not provided) - for native builds
33
+ *
34
+ * @param seccompBinaryPath - Optional explicit path to the apply-seccomp binary. If provided
35
+ * and exists, it will be used. If not provided, falls back to searching local paths and
36
+ * then global npm install (for native builds where vendor directory isn't bundled).
37
+ */
38
+ export declare function getApplySeccompBinaryPath(seccompBinaryPath?: string): string | null;
39
+ /**
40
+ * Get the path to a pre-generated seccomp BPF filter that blocks Unix domain socket creation
41
+ * Returns the path to the BPF filter file, or null if not available
42
+ *
43
+ * The filter blocks socket(AF_UNIX, ...) syscalls while allowing all other syscalls.
44
+ * This prevents creation of new Unix domain socket file descriptors.
45
+ *
46
+ * Security scope:
47
+ * - Blocks: socket(AF_UNIX, ...) syscall (creating new Unix socket FDs)
48
+ * - Does NOT block: Operations on inherited Unix socket FDs (bind, connect, sendto, etc.)
49
+ * - Does NOT block: Unix socket FDs passed via SCM_RIGHTS
50
+ * - For most sandboxing scenarios, blocking socket creation is sufficient
51
+ *
52
+ * Note: This blocks ALL Unix socket creation, regardless of path. The allowUnixSockets
53
+ * configuration is not supported on Linux due to seccomp-bpf limitations (it cannot
54
+ * read user-space memory to inspect socket paths).
55
+ *
56
+ * Requirements:
57
+ * - Pre-generated BPF filters included for x64 and ARM64 only
58
+ * - Other architectures are not supported
59
+ *
60
+ * @param seccompBinaryPath - Optional explicit path to the BPF filter file
61
+ * @returns Path to the pre-generated BPF filter file, or null if not available
62
+ */
63
+ export declare function generateSeccompFilter(seccompBinaryPath?: string): string | null;
64
+ /**
65
+ * Clean up a seccomp filter file
66
+ * Since we only use pre-generated BPF files from vendor/, this is a no-op.
67
+ * Pre-generated files are never deleted.
68
+ * Kept for backward compatibility with existing code that calls it.
69
+ */
70
+ export declare function cleanupSeccompFilter(_filterPath: string): void;
71
+ //# sourceMappingURL=generate-seccomp-filter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-seccomp-filter.d.ts","sourceRoot":"","sources":["../../src/sandbox/generate-seccomp-filter.ts"],"names":[],"mappings":"AA8IA;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,sBAAsB,CACpC,iBAAiB,CAAC,EAAE,MAAM,GACzB,MAAM,GAAG,IAAI,CASf;AA6DD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,yBAAyB,CACvC,iBAAiB,CAAC,EAAE,MAAM,GACzB,MAAM,GAAG,IAAI,CASf;AA6DD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,qBAAqB,CACnC,iBAAiB,CAAC,EAAE,MAAM,GACzB,MAAM,GAAG,IAAI,CAaf;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAE9D"}
@@ -0,0 +1,263 @@
1
+ import { join, dirname } from 'node:path';
2
+ import { fileURLToPath } from 'node:url';
3
+ import * as fs from 'node:fs';
4
+ import { execSync } from 'node:child_process';
5
+ import { homedir } from 'node:os';
6
+ import { logForDebugging } from '../utils/debug.js';
7
+ // Cache for path lookups (key: explicit path or empty string, value: resolved path or null)
8
+ const bpfPathCache = new Map();
9
+ const applySeccompPathCache = new Map();
10
+ // Cache for global npm paths (computed once per process)
11
+ let cachedGlobalNpmPaths = null;
12
+ /**
13
+ * Get paths to check for globally installed @anthropic-ai/sandbox-runtime package.
14
+ * This is used as a fallback when the binaries aren't bundled (e.g., native builds).
15
+ */
16
+ function getGlobalNpmPaths() {
17
+ if (cachedGlobalNpmPaths)
18
+ return cachedGlobalNpmPaths;
19
+ const paths = [];
20
+ // Try to get the actual global npm root
21
+ try {
22
+ const npmRoot = execSync('npm root -g', {
23
+ encoding: 'utf8',
24
+ timeout: 5000,
25
+ stdio: ['pipe', 'pipe', 'ignore'],
26
+ }).trim();
27
+ if (npmRoot) {
28
+ paths.push(join(npmRoot, '@anthropic-ai', 'sandbox-runtime'));
29
+ }
30
+ }
31
+ catch {
32
+ // npm not available or failed
33
+ }
34
+ // Common global npm locations as fallbacks
35
+ const home = homedir();
36
+ paths.push(
37
+ // npm global (Linux/macOS)
38
+ join('/usr', 'lib', 'node_modules', '@anthropic-ai', 'sandbox-runtime'), join('/usr', 'local', 'lib', 'node_modules', '@anthropic-ai', 'sandbox-runtime'),
39
+ // npm global with prefix (common on macOS with homebrew)
40
+ join('/opt', 'homebrew', 'lib', 'node_modules', '@anthropic-ai', 'sandbox-runtime'),
41
+ // User-local npm global
42
+ join(home, '.npm', 'lib', 'node_modules', '@anthropic-ai', 'sandbox-runtime'), join(home, '.npm-global', 'lib', 'node_modules', '@anthropic-ai', 'sandbox-runtime'));
43
+ cachedGlobalNpmPaths = paths;
44
+ return paths;
45
+ }
46
+ /**
47
+ * Map Node.js process.arch to our vendor directory architecture names
48
+ * Returns null for unsupported architectures
49
+ */
50
+ function getVendorArchitecture() {
51
+ const arch = process.arch;
52
+ switch (arch) {
53
+ case 'x64':
54
+ case 'x86_64':
55
+ return 'x64';
56
+ case 'arm64':
57
+ case 'aarch64':
58
+ return 'arm64';
59
+ case 'ia32':
60
+ case 'x86':
61
+ // TODO: Add support for 32-bit x86 (ia32)
62
+ // Currently blocked because the seccomp filter does not block the socketcall() syscall,
63
+ // which is used on 32-bit x86 for all socket operations (socket, socketpair, bind, connect, etc.).
64
+ // On 32-bit x86, the direct socket() syscall doesn't exist - instead, all socket operations
65
+ // are multiplexed through socketcall(SYS_SOCKET, ...), socketcall(SYS_SOCKETPAIR, ...), etc.
66
+ //
67
+ // To properly support 32-bit x86, we need to:
68
+ // 1. Build a separate i386 BPF filter (BPF bytecode is architecture-specific)
69
+ // 2. Modify vendor/seccomp-src/seccomp-unix-block.c to conditionally add rules that block:
70
+ // - socketcall(SYS_SOCKET, [AF_UNIX, ...])
71
+ // - socketcall(SYS_SOCKETPAIR, [AF_UNIX, ...])
72
+ // 3. This requires complex BPF logic to inspect socketcall's sub-function argument
73
+ //
74
+ // Until then, 32-bit x86 is not supported to avoid a security bypass.
75
+ logForDebugging(`[SeccompFilter] 32-bit x86 (ia32) is not currently supported due to missing socketcall() syscall blocking. ` +
76
+ `The current seccomp filter only blocks socket(AF_UNIX, ...), but on 32-bit x86, socketcall() can be used to bypass this.`, { level: 'error' });
77
+ return null;
78
+ default:
79
+ logForDebugging(`[SeccompFilter] Unsupported architecture: ${arch}. Only x64 and arm64 are supported.`);
80
+ return null;
81
+ }
82
+ }
83
+ /**
84
+ * Get local paths to check for seccomp files (bundled or package installs).
85
+ */
86
+ function getLocalSeccompPaths(filename) {
87
+ const arch = getVendorArchitecture();
88
+ if (!arch)
89
+ return [];
90
+ const baseDir = dirname(fileURLToPath(import.meta.url));
91
+ const relativePath = join('vendor', 'seccomp', arch, filename);
92
+ return [
93
+ join(baseDir, relativePath), // bundled: same directory as bundle (e.g., when bundled into claude-cli)
94
+ join(baseDir, '..', '..', relativePath), // package root: vendor/seccomp/...
95
+ join(baseDir, '..', relativePath), // dist: dist/vendor/seccomp/...
96
+ ];
97
+ }
98
+ /**
99
+ * Get the path to a pre-generated BPF filter file from the vendor directory
100
+ * Returns the path if it exists, null otherwise
101
+ *
102
+ * Pre-generated BPF files are organized by architecture:
103
+ * - vendor/seccomp/{x64,arm64}/unix-block.bpf
104
+ *
105
+ * Tries multiple paths for resilience:
106
+ * 0. Explicit path provided via parameter (checked first if provided)
107
+ * 1. vendor/seccomp/{arch}/unix-block.bpf (bundled - when bundled into consuming packages)
108
+ * 2. ../../vendor/seccomp/{arch}/unix-block.bpf (package root - standard npm installs)
109
+ * 3. ../vendor/seccomp/{arch}/unix-block.bpf (dist/vendor - for bundlers)
110
+ * 4. Global npm install (if seccompBinaryPath not provided) - for native builds
111
+ *
112
+ * @param seccompBinaryPath - Optional explicit path to the BPF filter file. If provided and
113
+ * exists, it will be used. If not provided, falls back to searching local paths and then
114
+ * global npm install (for native builds where vendor directory isn't bundled).
115
+ */
116
+ export function getPreGeneratedBpfPath(seccompBinaryPath) {
117
+ const cacheKey = seccompBinaryPath ?? '';
118
+ if (bpfPathCache.has(cacheKey)) {
119
+ return bpfPathCache.get(cacheKey);
120
+ }
121
+ const result = findBpfPath(seccompBinaryPath);
122
+ bpfPathCache.set(cacheKey, result);
123
+ return result;
124
+ }
125
+ // NOTE: This is a slow operation (synchronous fs lookups + execSync). Ensure calls
126
+ // are memoized at the top level rather than invoked repeatedly.
127
+ function findBpfPath(seccompBinaryPath) {
128
+ // Check explicit path first (highest priority)
129
+ if (seccompBinaryPath) {
130
+ if (fs.existsSync(seccompBinaryPath)) {
131
+ logForDebugging(`[SeccompFilter] Using BPF filter from explicit path: ${seccompBinaryPath}`);
132
+ return seccompBinaryPath;
133
+ }
134
+ logForDebugging(`[SeccompFilter] Explicit path provided but file not found: ${seccompBinaryPath}`);
135
+ }
136
+ const arch = getVendorArchitecture();
137
+ if (!arch) {
138
+ logForDebugging(`[SeccompFilter] Cannot find pre-generated BPF filter: unsupported architecture ${process.arch}`);
139
+ return null;
140
+ }
141
+ logForDebugging(`[SeccompFilter] Detected architecture: ${arch}`);
142
+ // Check local paths first (bundled or package install)
143
+ for (const bpfPath of getLocalSeccompPaths('unix-block.bpf')) {
144
+ if (fs.existsSync(bpfPath)) {
145
+ logForDebugging(`[SeccompFilter] Found pre-generated BPF filter: ${bpfPath} (${arch})`);
146
+ return bpfPath;
147
+ }
148
+ }
149
+ // Fallback: check global npm install (for native builds without bundled vendor)
150
+ for (const globalBase of getGlobalNpmPaths()) {
151
+ const bpfPath = join(globalBase, 'vendor', 'seccomp', arch, 'unix-block.bpf');
152
+ if (fs.existsSync(bpfPath)) {
153
+ logForDebugging(`[SeccompFilter] Found pre-generated BPF filter in global install: ${bpfPath} (${arch})`);
154
+ return bpfPath;
155
+ }
156
+ }
157
+ logForDebugging(`[SeccompFilter] Pre-generated BPF filter not found in any expected location (${arch})`);
158
+ return null;
159
+ }
160
+ /**
161
+ * Get the path to the apply-seccomp binary from the vendor directory
162
+ * Returns the path if it exists, null otherwise
163
+ *
164
+ * Pre-built apply-seccomp binaries are organized by architecture:
165
+ * - vendor/seccomp/{x64,arm64}/apply-seccomp
166
+ *
167
+ * Tries multiple paths for resilience:
168
+ * 0. Explicit path provided via parameter (checked first if provided)
169
+ * 1. vendor/seccomp/{arch}/apply-seccomp (bundled - when bundled into consuming packages)
170
+ * 2. ../../vendor/seccomp/{arch}/apply-seccomp (package root - standard npm installs)
171
+ * 3. ../vendor/seccomp/{arch}/apply-seccomp (dist/vendor - for bundlers)
172
+ * 4. Global npm install (if seccompBinaryPath not provided) - for native builds
173
+ *
174
+ * @param seccompBinaryPath - Optional explicit path to the apply-seccomp binary. If provided
175
+ * and exists, it will be used. If not provided, falls back to searching local paths and
176
+ * then global npm install (for native builds where vendor directory isn't bundled).
177
+ */
178
+ export function getApplySeccompBinaryPath(seccompBinaryPath) {
179
+ const cacheKey = seccompBinaryPath ?? '';
180
+ if (applySeccompPathCache.has(cacheKey)) {
181
+ return applySeccompPathCache.get(cacheKey);
182
+ }
183
+ const result = findApplySeccompPath(seccompBinaryPath);
184
+ applySeccompPathCache.set(cacheKey, result);
185
+ return result;
186
+ }
187
+ function findApplySeccompPath(seccompBinaryPath) {
188
+ // Check explicit path first (highest priority)
189
+ if (seccompBinaryPath) {
190
+ if (fs.existsSync(seccompBinaryPath)) {
191
+ logForDebugging(`[SeccompFilter] Using apply-seccomp binary from explicit path: ${seccompBinaryPath}`);
192
+ return seccompBinaryPath;
193
+ }
194
+ logForDebugging(`[SeccompFilter] Explicit path provided but file not found: ${seccompBinaryPath}`);
195
+ }
196
+ const arch = getVendorArchitecture();
197
+ if (!arch) {
198
+ logForDebugging(`[SeccompFilter] Cannot find apply-seccomp binary: unsupported architecture ${process.arch}`);
199
+ return null;
200
+ }
201
+ logForDebugging(`[SeccompFilter] Looking for apply-seccomp binary for architecture: ${arch}`);
202
+ // Check local paths first (bundled or package install)
203
+ for (const binaryPath of getLocalSeccompPaths('apply-seccomp')) {
204
+ if (fs.existsSync(binaryPath)) {
205
+ logForDebugging(`[SeccompFilter] Found apply-seccomp binary: ${binaryPath} (${arch})`);
206
+ return binaryPath;
207
+ }
208
+ }
209
+ // Fallback: check global npm install (for native builds without bundled vendor)
210
+ for (const globalBase of getGlobalNpmPaths()) {
211
+ const binaryPath = join(globalBase, 'vendor', 'seccomp', arch, 'apply-seccomp');
212
+ if (fs.existsSync(binaryPath)) {
213
+ logForDebugging(`[SeccompFilter] Found apply-seccomp binary in global install: ${binaryPath} (${arch})`);
214
+ return binaryPath;
215
+ }
216
+ }
217
+ logForDebugging(`[SeccompFilter] apply-seccomp binary not found in any expected location (${arch})`);
218
+ return null;
219
+ }
220
+ /**
221
+ * Get the path to a pre-generated seccomp BPF filter that blocks Unix domain socket creation
222
+ * Returns the path to the BPF filter file, or null if not available
223
+ *
224
+ * The filter blocks socket(AF_UNIX, ...) syscalls while allowing all other syscalls.
225
+ * This prevents creation of new Unix domain socket file descriptors.
226
+ *
227
+ * Security scope:
228
+ * - Blocks: socket(AF_UNIX, ...) syscall (creating new Unix socket FDs)
229
+ * - Does NOT block: Operations on inherited Unix socket FDs (bind, connect, sendto, etc.)
230
+ * - Does NOT block: Unix socket FDs passed via SCM_RIGHTS
231
+ * - For most sandboxing scenarios, blocking socket creation is sufficient
232
+ *
233
+ * Note: This blocks ALL Unix socket creation, regardless of path. The allowUnixSockets
234
+ * configuration is not supported on Linux due to seccomp-bpf limitations (it cannot
235
+ * read user-space memory to inspect socket paths).
236
+ *
237
+ * Requirements:
238
+ * - Pre-generated BPF filters included for x64 and ARM64 only
239
+ * - Other architectures are not supported
240
+ *
241
+ * @param seccompBinaryPath - Optional explicit path to the BPF filter file
242
+ * @returns Path to the pre-generated BPF filter file, or null if not available
243
+ */
244
+ export function generateSeccompFilter(seccompBinaryPath) {
245
+ const preGeneratedBpf = getPreGeneratedBpfPath(seccompBinaryPath);
246
+ if (preGeneratedBpf) {
247
+ logForDebugging('[SeccompFilter] Using pre-generated BPF filter');
248
+ return preGeneratedBpf;
249
+ }
250
+ logForDebugging('[SeccompFilter] Pre-generated BPF filter not available for this architecture. ' +
251
+ 'Only x64 and arm64 are supported.', { level: 'error' });
252
+ return null;
253
+ }
254
+ /**
255
+ * Clean up a seccomp filter file
256
+ * Since we only use pre-generated BPF files from vendor/, this is a no-op.
257
+ * Pre-generated files are never deleted.
258
+ * Kept for backward compatibility with existing code that calls it.
259
+ */
260
+ export function cleanupSeccompFilter(_filterPath) {
261
+ // No-op: pre-generated BPF files are never cleaned up
262
+ }
263
+ //# sourceMappingURL=generate-seccomp-filter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-seccomp-filter.js","sourceRoot":"","sources":["../../src/sandbox/generate-seccomp-filter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,KAAK,EAAE,MAAM,SAAS,CAAA;AAC7B,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AACjC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAEnD,4FAA4F;AAC5F,MAAM,YAAY,GAAG,IAAI,GAAG,EAAyB,CAAA;AACrD,MAAM,qBAAqB,GAAG,IAAI,GAAG,EAAyB,CAAA;AAE9D,yDAAyD;AACzD,IAAI,oBAAoB,GAAoB,IAA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 'node:net';
2
+ import type { Duplex } from 'node:stream';
3
+ export interface HttpProxyServerOptions {
4
+ filter(port: number, host: string, socket: Socket | Duplex): Promise<boolean> | boolean;
5
+ /**
6
+ * Optional function to get the MITM proxy socket path for a given host.
7
+ * If returns a socket path, the request will be routed through that MITM proxy.
8
+ * If returns undefined, the request will be handled directly.
9
+ */
10
+ getMitmSocketPath?(host: string): string | undefined;
11
+ }
12
+ export declare function createHttpProxyServer(options: HttpProxyServerOptions): Server;
13
+ //# sourceMappingURL=http-proxy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http-proxy.d.ts","sourceRoot":"","sources":["../../src/sandbox/http-proxy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAC9C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAQzC,MAAM,WAAW,sBAAsB;IACrC,MAAM,CACJ,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,GAAG,MAAM,GACtB,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAA;IAE7B;;;;OAIG;IACH,iBAAiB,CAAC,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;CACrD;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,sBAAsB,GAAG,MAAM,CA6P7E"}