@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":"sandbox-manager.js","sourceRoot":"","sources":["../../src/sandbox/sandbox-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,iBAAiB,CAAA;AACvD,OAAO,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAA;AAEzD,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AACrC,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACjE,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AAQxB,OAAO,EACL,2BAA2B,EAC3B,4BAA4B,EAE5B,sBAAsB,EAEtB,uBAAuB,GACxB,MAAM,0BAA0B,CAAA;AACjC,OAAO,EACL,2BAA2B,EAC3B,2BAA2B,GAC5B,MAAM,0BAA0B,CAAA;AACjC,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,wBAAwB,EACxB,iBAAiB,GAClB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,qBAAqB,EAAE,MAAM,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`undefined` = no restrictions (allow all reads)
6
+ * - `{denyOnly: []}` = no restrictions (empty deny list = allow all reads)
7
+ * - `{denyOnly: [...paths]}` = deny reads from these paths, allow all others
8
+ * - `{denyOnly: [...paths], allowWithinDeny: [...paths]}` = deny reads from
9
+ * denyOnly paths, but re-allow reads within allowWithinDeny paths.
10
+ * allowWithinDeny takes precedence over denyOnly (most-specific rule wins).
11
+ *
12
+ * This is maximally permissive by default - only explicitly denied paths are blocked.
13
+ */
14
+ export interface FsReadRestrictionConfig {
15
+ denyOnly: string[];
16
+ allowWithinDeny?: string[];
17
+ }
18
+ /**
19
+ * Write restriction config using an "allow-only" pattern.
20
+ *
21
+ * Semantics:
22
+ * - `undefined` = no restrictions (allow all writes)
23
+ * - `{allowOnly: [], denyWithinAllow: []}` = maximally restrictive (deny ALL writes)
24
+ * - `{allowOnly: [...paths], denyWithinAllow: [...]}` = allow writes only to these paths,
25
+ * with exceptions for denyWithinAllow
26
+ *
27
+ * This is maximally restrictive by default - only explicitly allowed paths are writable.
28
+ * Note: Empty `allowOnly` means NO paths are writable (unlike read's empty denyOnly).
29
+ */
30
+ export interface FsWriteRestrictionConfig {
31
+ allowOnly: string[];
32
+ denyWithinAllow: string[];
33
+ }
34
+ /**
35
+ * Network restriction config (internal structure built from permission rules).
36
+ *
37
+ * This uses an "allow-only" pattern (like write restrictions):
38
+ * - `allowedHosts` = hosts that are explicitly allowed
39
+ * - `deniedHosts` = hosts that are explicitly denied (checked first, before allowedHosts)
40
+ *
41
+ * Semantics:
42
+ * - `undefined` = maximally restrictive (deny all network)
43
+ * - `{allowedHosts: [], deniedHosts: []}` = maximally restrictive (nothing allowed)
44
+ * - `{allowedHosts: [...], deniedHosts: [...]}` = apply allow/deny rules
45
+ *
46
+ * Note: Empty `allowedHosts` means NO hosts are allowed (unlike read's empty denyOnly).
47
+ */
48
+ export interface NetworkRestrictionConfig {
49
+ allowedHosts?: string[];
50
+ deniedHosts?: string[];
51
+ }
52
+ export type NetworkHostPattern = {
53
+ host: string;
54
+ port: number | undefined;
55
+ };
56
+ export type SandboxAskCallback = (params: NetworkHostPattern) => Promise<boolean>;
57
+ //# sourceMappingURL=sandbox-schemas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sandbox-schemas.d.ts","sourceRoot":"","sources":["../../src/sandbox/sandbox-schemas.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,uBAAuB;IACtC,QAAQ,EAAE,MAAM,EAAE,CAAA;IAClB,eAAe,CAAC,EAAE,MAAM,EAAE,CAAA;CAC3B;AAED;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,wBAAwB;IACvC,SAAS,EAAE,MAAM,EAAE,CAAA;IACnB,eAAe,EAAE,MAAM,EAAE,CAAA;CAC1B;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,wBAAwB;IACvC,YAAY,CAAC,EAAE,MAAM,EAAE,CAAA;IACvB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAA;CACvB;AAED,MAAM,MAAM,kBAAkB,GAAG;IAC/B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,GAAG,SAAS,CAAA;CACzB,CAAA;AAED,MAAM,MAAM,kBAAkB,GAAG,CAC/B,MAAM,EAAE,kBAAkB,KACvB,OAAO,CAAC,OAAO,CAAC,CAAA"}
@@ -0,0 +1,3 @@
1
+ // Filesystem restriction configs (internal structures built from permission rules)
2
+ export {};
3
+ //# sourceMappingURL=sandbox-schemas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sandbox-schemas.js","sourceRoot":"","sources":["../../src/sandbox/sandbox-schemas.ts"],"names":[],"mappings":"AAAA,mFAAmF"}
@@ -0,0 +1,109 @@
1
+ /**
2
+ * Dangerous files that should be protected from writes.
3
+ * These files can be used for code execution or data exfiltration.
4
+ */
5
+ export declare const DANGEROUS_FILES: readonly [".gitconfig", ".gitmodules", ".bashrc", ".bash_profile", ".zshrc", ".zprofile", ".profile", ".ripgreprc", ".mcp.json"];
6
+ /**
7
+ * Dangerous directories that should be protected from writes.
8
+ * These directories contain sensitive configuration or executable files.
9
+ */
10
+ export declare const DANGEROUS_DIRECTORIES: readonly [".git", ".vscode", ".idea"];
11
+ /**
12
+ * Get the list of dangerous directories to deny writes to.
13
+ * Excludes .git since we need it writable for git operations -
14
+ * instead we block specific paths within .git (hooks and config).
15
+ */
16
+ export declare function getDangerousDirectories(): string[];
17
+ /**
18
+ * Normalizes a path for case-insensitive comparison.
19
+ * This prevents bypassing security checks using mixed-case paths on case-insensitive
20
+ * filesystems (macOS/Windows) like `.cLauDe/Settings.locaL.json`.
21
+ *
22
+ * We always normalize to lowercase regardless of platform for consistent security.
23
+ * @param path The path to normalize
24
+ * @returns The lowercase path for safe comparison
25
+ */
26
+ export declare function normalizeCaseForComparison(pathStr: string): string;
27
+ /**
28
+ * Check if a path pattern contains glob characters
29
+ */
30
+ export declare function containsGlobChars(pathPattern: string): boolean;
31
+ /**
32
+ * Remove trailing /** glob suffix from a path pattern
33
+ * Used to normalize path patterns since /** just means "directory and everything under it"
34
+ */
35
+ export declare function removeTrailingGlobSuffix(pathPattern: string): string;
36
+ /**
37
+ * Check if a symlink resolution crosses expected path boundaries.
38
+ *
39
+ * When resolving symlinks for sandbox path normalization, we need to ensure
40
+ * the resolved path doesn't unexpectedly broaden the scope. This function
41
+ * returns true if the resolved path is an ancestor of the original path
42
+ * or resolves to a system root, which would indicate the symlink points
43
+ * outside expected boundaries.
44
+ *
45
+ * @param originalPath - The original path before symlink resolution
46
+ * @param resolvedPath - The path after fs.realpathSync() resolution
47
+ * @returns true if the resolved path is outside expected boundaries
48
+ */
49
+ export declare function isSymlinkOutsideBoundary(originalPath: string, resolvedPath: string): boolean;
50
+ /**
51
+ * Normalize a path for use in sandbox configurations
52
+ * Handles:
53
+ * - Tilde (~) expansion for home directory
54
+ * - Relative paths (./foo, ../foo, etc.) converted to absolute
55
+ * - Absolute paths remain unchanged
56
+ * - Symlinks are resolved to their real paths for non-glob patterns
57
+ * - Glob patterns preserve wildcards after path normalization
58
+ *
59
+ * Returns the absolute path with symlinks resolved (or normalized glob pattern)
60
+ */
61
+ export declare function normalizePathForSandbox(pathPattern: string): string;
62
+ /**
63
+ * Get recommended system paths that should be writable for commands to work properly
64
+ *
65
+ * WARNING: These default paths are intentionally broad for compatibility but may
66
+ * allow access to files from other processes. In highly security-sensitive
67
+ * environments, you should configure more restrictive write paths.
68
+ */
69
+ export declare function getDefaultWritePaths(): string[];
70
+ /**
71
+ * Generate proxy environment variables for sandboxed processes
72
+ */
73
+ export declare function generateProxyEnvVars(httpProxyPort?: number, socksProxyPort?: number): string[];
74
+ /**
75
+ * Encode a command for sandbox monitoring
76
+ * Truncates to 100 chars and base64 encodes to avoid parsing issues
77
+ */
78
+ export declare function encodeSandboxedCommand(command: string): string;
79
+ /**
80
+ * Decode a base64-encoded command from sandbox monitoring
81
+ */
82
+ export declare function decodeSandboxedCommand(encodedCommand: string): string;
83
+ /**
84
+ * Convert a glob pattern to a regular expression
85
+ *
86
+ * This implements gitignore-style pattern matching to match the behavior of the
87
+ * `ignore` library used by the permission system.
88
+ *
89
+ * Supported patterns:
90
+ * - * matches any characters except / (e.g., *.ts matches foo.ts but not foo/bar.ts)
91
+ * - ** matches any characters including / (e.g., src/**\/*.ts matches all .ts files in src/)
92
+ * - ? matches any single character except / (e.g., file?.txt matches file1.txt)
93
+ * - [abc] matches any character in the set (e.g., file[0-9].txt matches file3.txt)
94
+ *
95
+ * Exported for testing and shared between macOS sandbox profiles and Linux glob expansion.
96
+ */
97
+ export declare function globToRegex(globPattern: string): string;
98
+ /**
99
+ * Expand a glob pattern into concrete file paths.
100
+ *
101
+ * Used on Linux where bubblewrap doesn't support glob patterns natively.
102
+ * Resolves the static directory prefix, lists files recursively, and filters
103
+ * using globToRegex().
104
+ *
105
+ * @param globPath - A path pattern containing glob characters (e.g., ~/test/*.env)
106
+ * @returns Array of absolute paths matching the glob pattern
107
+ */
108
+ export declare function expandGlobPattern(globPath: string): string[];
109
+ //# sourceMappingURL=sandbox-utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sandbox-utils.d.ts","sourceRoot":"","sources":["../../src/sandbox/sandbox-utils.ts"],"names":[],"mappings":"AAMA;;;GAGG;AACH,eAAO,MAAM,eAAe,kIAUlB,CAAA;AAEV;;;GAGG;AACH,eAAO,MAAM,qBAAqB,uCAAwC,CAAA;AAE1E;;;;GAIG;AACH,wBAAgB,uBAAuB,IAAI,MAAM,EAAE,CAMlD;AAED;;;;;;;;GAQG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAElE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAO9D;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAGpE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,wBAAwB,CACtC,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,GACnB,OAAO,CAuGT;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CA6DnE;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,EAAE,CAgB/C;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,aAAa,CAAC,EAAE,MAAM,EACtB,cAAc,CAAC,EAAE,MAAM,GACtB,MAAM,EAAE,CAgGV;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAG9D;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,cAAc,EAAE,MAAM,GAAG,MAAM,CAErE;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAkBvD;AAED;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,EAAE,CAsD5D"}
@@ -0,0 +1,429 @@
1
+ import { homedir } from 'os';
2
+ import * as path from 'path';
3
+ import * as fs from 'fs';
4
+ import { getPlatform } from '../utils/platform.js';
5
+ import { logForDebugging } from '../utils/debug.js';
6
+ /**
7
+ * Dangerous files that should be protected from writes.
8
+ * These files can be used for code execution or data exfiltration.
9
+ */
10
+ export const DANGEROUS_FILES = [
11
+ '.gitconfig',
12
+ '.gitmodules',
13
+ '.bashrc',
14
+ '.bash_profile',
15
+ '.zshrc',
16
+ '.zprofile',
17
+ '.profile',
18
+ '.ripgreprc',
19
+ '.mcp.json',
20
+ ];
21
+ /**
22
+ * Dangerous directories that should be protected from writes.
23
+ * These directories contain sensitive configuration or executable files.
24
+ */
25
+ export const DANGEROUS_DIRECTORIES = ['.git', '.vscode', '.idea'];
26
+ /**
27
+ * Get the list of dangerous directories to deny writes to.
28
+ * Excludes .git since we need it writable for git operations -
29
+ * instead we block specific paths within .git (hooks and config).
30
+ */
31
+ export function getDangerousDirectories() {
32
+ return [
33
+ ...DANGEROUS_DIRECTORIES.filter(d => d !== '.git'),
34
+ '.claude/commands',
35
+ '.claude/agents',
36
+ ];
37
+ }
38
+ /**
39
+ * Normalizes a path for case-insensitive comparison.
40
+ * This prevents bypassing security checks using mixed-case paths on case-insensitive
41
+ * filesystems (macOS/Windows) like `.cLauDe/Settings.locaL.json`.
42
+ *
43
+ * We always normalize to lowercase regardless of platform for consistent security.
44
+ * @param path The path to normalize
45
+ * @returns The lowercase path for safe comparison
46
+ */
47
+ export function normalizeCaseForComparison(pathStr) {
48
+ return pathStr.toLowerCase();
49
+ }
50
+ /**
51
+ * Check if a path pattern contains glob characters
52
+ */
53
+ export function containsGlobChars(pathPattern) {
54
+ return (pathPattern.includes('*') ||
55
+ pathPattern.includes('?') ||
56
+ pathPattern.includes('[') ||
57
+ pathPattern.includes(']'));
58
+ }
59
+ /**
60
+ * Remove trailing /** glob suffix from a path pattern
61
+ * Used to normalize path patterns since /** just means "directory and everything under it"
62
+ */
63
+ export function removeTrailingGlobSuffix(pathPattern) {
64
+ const stripped = pathPattern.replace(/\/\*\*$/, '');
65
+ return stripped || '/';
66
+ }
67
+ /**
68
+ * Check if a symlink resolution crosses expected path boundaries.
69
+ *
70
+ * When resolving symlinks for sandbox path normalization, we need to ensure
71
+ * the resolved path doesn't unexpectedly broaden the scope. This function
72
+ * returns true if the resolved path is an ancestor of the original path
73
+ * or resolves to a system root, which would indicate the symlink points
74
+ * outside expected boundaries.
75
+ *
76
+ * @param originalPath - The original path before symlink resolution
77
+ * @param resolvedPath - The path after fs.realpathSync() resolution
78
+ * @returns true if the resolved path is outside expected boundaries
79
+ */
80
+ export function isSymlinkOutsideBoundary(originalPath, resolvedPath) {
81
+ const normalizedOriginal = path.normalize(originalPath);
82
+ const normalizedResolved = path.normalize(resolvedPath);
83
+ // Same path after normalization - OK
84
+ if (normalizedResolved === normalizedOriginal) {
85
+ return false;
86
+ }
87
+ // Handle macOS /tmp -> /private/tmp canonical resolution
88
+ // This is a legitimate system symlink that should be allowed
89
+ // /tmp/claude -> /private/tmp/claude is OK
90
+ // /var/folders/... -> /private/var/folders/... is OK
91
+ if (normalizedOriginal.startsWith('/tmp/') &&
92
+ normalizedResolved === '/private' + normalizedOriginal) {
93
+ return false;
94
+ }
95
+ if (normalizedOriginal.startsWith('/var/') &&
96
+ normalizedResolved === '/private' + normalizedOriginal) {
97
+ return false;
98
+ }
99
+ // Also handle the reverse: /private/tmp/... resolving to itself
100
+ if (normalizedOriginal.startsWith('/private/tmp/') &&
101
+ normalizedResolved === normalizedOriginal) {
102
+ return false;
103
+ }
104
+ if (normalizedOriginal.startsWith('/private/var/') &&
105
+ normalizedResolved === normalizedOriginal) {
106
+ return false;
107
+ }
108
+ // If resolved path is "/" it's outside expected boundaries
109
+ if (normalizedResolved === '/') {
110
+ return true;
111
+ }
112
+ // If resolved path is very short (single component like /tmp, /usr, /var),
113
+ // it's likely outside expected boundaries
114
+ const resolvedParts = normalizedResolved.split('/').filter(Boolean);
115
+ if (resolvedParts.length <= 1) {
116
+ return true;
117
+ }
118
+ // If original path starts with resolved path, the resolved path is an ancestor
119
+ // e.g., /tmp/claude -> /tmp means the symlink points to a broader scope
120
+ if (normalizedOriginal.startsWith(normalizedResolved + '/')) {
121
+ return true;
122
+ }
123
+ // Also check the canonical form of the original path for macOS
124
+ // e.g., /tmp/claude should also be checked as /private/tmp/claude
125
+ let canonicalOriginal = normalizedOriginal;
126
+ if (normalizedOriginal.startsWith('/tmp/')) {
127
+ canonicalOriginal = '/private' + normalizedOriginal;
128
+ }
129
+ else if (normalizedOriginal.startsWith('/var/')) {
130
+ canonicalOriginal = '/private' + normalizedOriginal;
131
+ }
132
+ if (canonicalOriginal !== normalizedOriginal &&
133
+ canonicalOriginal.startsWith(normalizedResolved + '/')) {
134
+ return true;
135
+ }
136
+ // STRICT CHECK: Only allow resolutions that stay within the expected path tree
137
+ // The resolved path must either:
138
+ // 1. Start with the original path (deeper/same) - already covered by returning false below
139
+ // 2. Start with the canonical original (deeper/same under canonical form)
140
+ // 3. BE the canonical form of the original (e.g., /tmp/x -> /private/tmp/x)
141
+ // Any other resolution (e.g., /tmp/claude -> /Users/dworken) is outside expected bounds
142
+ const resolvedStartsWithOriginal = normalizedResolved.startsWith(normalizedOriginal + '/');
143
+ const resolvedStartsWithCanonical = canonicalOriginal !== normalizedOriginal &&
144
+ normalizedResolved.startsWith(canonicalOriginal + '/');
145
+ const resolvedIsCanonical = canonicalOriginal !== normalizedOriginal &&
146
+ normalizedResolved === canonicalOriginal;
147
+ const resolvedIsSame = normalizedResolved === normalizedOriginal;
148
+ // If resolved path is not within expected tree, it's outside boundary
149
+ if (!resolvedIsSame &&
150
+ !resolvedIsCanonical &&
151
+ !resolvedStartsWithOriginal &&
152
+ !resolvedStartsWithCanonical) {
153
+ return true;
154
+ }
155
+ // Allow resolution to same directory level or deeper within expected tree
156
+ return false;
157
+ }
158
+ /**
159
+ * Normalize a path for use in sandbox configurations
160
+ * Handles:
161
+ * - Tilde (~) expansion for home directory
162
+ * - Relative paths (./foo, ../foo, etc.) converted to absolute
163
+ * - Absolute paths remain unchanged
164
+ * - Symlinks are resolved to their real paths for non-glob patterns
165
+ * - Glob patterns preserve wildcards after path normalization
166
+ *
167
+ * Returns the absolute path with symlinks resolved (or normalized glob pattern)
168
+ */
169
+ export function normalizePathForSandbox(pathPattern) {
170
+ const cwd = process.cwd();
171
+ let normalizedPath = pathPattern;
172
+ // Expand ~ to home directory
173
+ if (pathPattern === '~') {
174
+ normalizedPath = homedir();
175
+ }
176
+ else if (pathPattern.startsWith('~/')) {
177
+ normalizedPath = homedir() + pathPattern.slice(1);
178
+ }
179
+ else if (pathPattern.startsWith('./') || pathPattern.startsWith('../')) {
180
+ // Convert relative to absolute based on current working directory
181
+ normalizedPath = path.resolve(cwd, pathPattern);
182
+ }
183
+ else if (!path.isAbsolute(pathPattern)) {
184
+ // Handle other relative paths (e.g., ".", "..", "foo/bar")
185
+ normalizedPath = path.resolve(cwd, pathPattern);
186
+ }
187
+ // For glob patterns, resolve symlinks for the directory portion only
188
+ if (containsGlobChars(normalizedPath)) {
189
+ // Extract the static directory prefix before glob characters
190
+ const staticPrefix = normalizedPath.split(/[*?[\]]/)[0];
191
+ if (staticPrefix && staticPrefix !== '/') {
192
+ // Get the directory containing the glob pattern
193
+ // If staticPrefix ends with /, remove it to get the directory
194
+ const baseDir = staticPrefix.endsWith('/')
195
+ ? staticPrefix.slice(0, -1)
196
+ : path.dirname(staticPrefix);
197
+ // Try to resolve symlinks for the base directory
198
+ try {
199
+ const resolvedBaseDir = fs.realpathSync(baseDir);
200
+ // Validate that resolution stays within expected boundaries
201
+ if (!isSymlinkOutsideBoundary(baseDir, resolvedBaseDir)) {
202
+ // Reconstruct the pattern with the resolved directory
203
+ const patternSuffix = normalizedPath.slice(baseDir.length);
204
+ return resolvedBaseDir + patternSuffix;
205
+ }
206
+ // If resolution would broaden scope, keep original pattern
207
+ }
208
+ catch {
209
+ // If directory doesn't exist or can't be resolved, keep the original pattern
210
+ }
211
+ }
212
+ return normalizedPath;
213
+ }
214
+ // Resolve symlinks to real paths to avoid bwrap issues
215
+ // Validate that the resolution stays within expected boundaries
216
+ try {
217
+ const resolvedPath = fs.realpathSync(normalizedPath);
218
+ // Only use resolved path if it doesn't cross boundary (e.g., symlink to parent dir)
219
+ if (isSymlinkOutsideBoundary(normalizedPath, resolvedPath)) {
220
+ // Symlink points outside expected boundaries - keep original path
221
+ }
222
+ else {
223
+ normalizedPath = resolvedPath;
224
+ }
225
+ }
226
+ catch {
227
+ // If path doesn't exist or can't be resolved, keep the normalized path
228
+ }
229
+ return normalizedPath;
230
+ }
231
+ /**
232
+ * Get recommended system paths that should be writable for commands to work properly
233
+ *
234
+ * WARNING: These default paths are intentionally broad for compatibility but may
235
+ * allow access to files from other processes. In highly security-sensitive
236
+ * environments, you should configure more restrictive write paths.
237
+ */
238
+ export function getDefaultWritePaths() {
239
+ const homeDir = homedir();
240
+ const recommendedPaths = [
241
+ '/dev/stdout',
242
+ '/dev/stderr',
243
+ '/dev/null',
244
+ '/dev/tty',
245
+ '/dev/dtracehelper',
246
+ '/dev/autofs_nowait',
247
+ '/tmp/claude',
248
+ '/private/tmp/claude',
249
+ path.join(homeDir, '.npm/_logs'),
250
+ path.join(homeDir, '.claude/debug'),
251
+ ];
252
+ return recommendedPaths;
253
+ }
254
+ /**
255
+ * Generate proxy environment variables for sandboxed processes
256
+ */
257
+ export function generateProxyEnvVars(httpProxyPort, socksProxyPort) {
258
+ // Respect CLAUDE_TMPDIR if set, otherwise default to /tmp/claude
259
+ const tmpdir = process.env.CLAUDE_TMPDIR || '/tmp/claude';
260
+ const envVars = [`SANDBOX_RUNTIME=1`, `TMPDIR=${tmpdir}`];
261
+ // If no proxy ports provided, return minimal env vars
262
+ if (!httpProxyPort && !socksProxyPort) {
263
+ return envVars;
264
+ }
265
+ // Always set NO_PROXY to exclude localhost and private networks from proxying
266
+ const noProxyAddresses = [
267
+ 'localhost',
268
+ '127.0.0.1',
269
+ '::1',
270
+ '*.local',
271
+ '.local',
272
+ '169.254.0.0/16', // Link-local
273
+ '10.0.0.0/8', // Private network
274
+ '172.16.0.0/12', // Private network
275
+ '192.168.0.0/16', // Private network
276
+ ].join(',');
277
+ envVars.push(`NO_PROXY=${noProxyAddresses}`);
278
+ envVars.push(`no_proxy=${noProxyAddresses}`);
279
+ if (httpProxyPort) {
280
+ envVars.push(`HTTP_PROXY=http://localhost:${httpProxyPort}`);
281
+ envVars.push(`HTTPS_PROXY=http://localhost:${httpProxyPort}`);
282
+ // Lowercase versions for compatibility with some tools
283
+ envVars.push(`http_proxy=http://localhost:${httpProxyPort}`);
284
+ envVars.push(`https_proxy=http://localhost:${httpProxyPort}`);
285
+ }
286
+ if (socksProxyPort) {
287
+ // Use socks5h:// for proper DNS resolution through proxy
288
+ envVars.push(`ALL_PROXY=socks5h://localhost:${socksProxyPort}`);
289
+ envVars.push(`all_proxy=socks5h://localhost:${socksProxyPort}`);
290
+ // Configure Git to use SSH through SOCKS proxy (platform-aware)
291
+ if (getPlatform() === 'macos') {
292
+ // macOS has nc available
293
+ // Note: No outer quotes - bwrap --setenv sets the value directly without shell interpretation
294
+ envVars.push(`GIT_SSH_COMMAND=ssh -o ProxyCommand='nc -X 5 -x localhost:${socksProxyPort} %h %p'`);
295
+ }
296
+ // FTP proxy support (use socks5h for DNS resolution through proxy)
297
+ envVars.push(`FTP_PROXY=socks5h://localhost:${socksProxyPort}`);
298
+ envVars.push(`ftp_proxy=socks5h://localhost:${socksProxyPort}`);
299
+ // rsync proxy support
300
+ envVars.push(`RSYNC_PROXY=localhost:${socksProxyPort}`);
301
+ // Database tools NOTE: Most database clients don't have built-in proxy support
302
+ // You typically need to use SSH tunneling or a SOCKS wrapper like tsocks/proxychains
303
+ // Docker CLI uses HTTP for the API
304
+ // This makes Docker use the HTTP proxy for registry operations
305
+ envVars.push(`DOCKER_HTTP_PROXY=http://localhost:${httpProxyPort || socksProxyPort}`);
306
+ envVars.push(`DOCKER_HTTPS_PROXY=http://localhost:${httpProxyPort || socksProxyPort}`);
307
+ // Kubernetes kubectl - uses standard HTTPS_PROXY
308
+ // kubectl respects HTTPS_PROXY which we already set above
309
+ // AWS CLI - uses standard HTTPS_PROXY (v2 supports it well)
310
+ // AWS CLI v2 respects HTTPS_PROXY which we already set above
311
+ // Google Cloud SDK - has specific proxy settings
312
+ // Use HTTPS proxy to match other HTTP-based tools
313
+ if (httpProxyPort) {
314
+ envVars.push(`CLOUDSDK_PROXY_TYPE=https`);
315
+ envVars.push(`CLOUDSDK_PROXY_ADDRESS=localhost`);
316
+ envVars.push(`CLOUDSDK_PROXY_PORT=${httpProxyPort}`);
317
+ }
318
+ // Azure CLI - uses HTTPS_PROXY
319
+ // Azure CLI respects HTTPS_PROXY which we already set above
320
+ // Terraform - uses standard HTTP/HTTPS proxy vars
321
+ // Terraform respects HTTP_PROXY/HTTPS_PROXY which we already set above
322
+ // gRPC-based tools - use standard proxy vars
323
+ envVars.push(`GRPC_PROXY=socks5h://localhost:${socksProxyPort}`);
324
+ envVars.push(`grpc_proxy=socks5h://localhost:${socksProxyPort}`);
325
+ }
326
+ // WARNING: Do not set HTTP_PROXY/HTTPS_PROXY to SOCKS URLs when only SOCKS proxy is available
327
+ // Most HTTP clients do not support SOCKS URLs in these variables and will fail, and we want
328
+ // to avoid overriding the client otherwise respecting the ALL_PROXY env var which points to SOCKS.
329
+ return envVars;
330
+ }
331
+ /**
332
+ * Encode a command for sandbox monitoring
333
+ * Truncates to 100 chars and base64 encodes to avoid parsing issues
334
+ */
335
+ export function encodeSandboxedCommand(command) {
336
+ const truncatedCommand = command.slice(0, 100);
337
+ return Buffer.from(truncatedCommand).toString('base64');
338
+ }
339
+ /**
340
+ * Decode a base64-encoded command from sandbox monitoring
341
+ */
342
+ export function decodeSandboxedCommand(encodedCommand) {
343
+ return Buffer.from(encodedCommand, 'base64').toString('utf8');
344
+ }
345
+ /**
346
+ * Convert a glob pattern to a regular expression
347
+ *
348
+ * This implements gitignore-style pattern matching to match the behavior of the
349
+ * `ignore` library used by the permission system.
350
+ *
351
+ * Supported patterns:
352
+ * - * matches any characters except / (e.g., *.ts matches foo.ts but not foo/bar.ts)
353
+ * - ** matches any characters including / (e.g., src/**\/*.ts matches all .ts files in src/)
354
+ * - ? matches any single character except / (e.g., file?.txt matches file1.txt)
355
+ * - [abc] matches any character in the set (e.g., file[0-9].txt matches file3.txt)
356
+ *
357
+ * Exported for testing and shared between macOS sandbox profiles and Linux glob expansion.
358
+ */
359
+ export function globToRegex(globPattern) {
360
+ return ('^' +
361
+ globPattern
362
+ // Escape regex special characters (except glob chars * ? [ ])
363
+ .replace(/[.^$+{}()|\\]/g, '\\$&')
364
+ // Escape unclosed brackets (no matching ])
365
+ .replace(/\[([^\]]*?)$/g, '\\[$1')
366
+ // Convert glob patterns to regex (order matters - ** before *)
367
+ .replace(/\*\*\//g, '__GLOBSTAR_SLASH__') // Placeholder for **/
368
+ .replace(/\*\*/g, '__GLOBSTAR__') // Placeholder for **
369
+ .replace(/\*/g, '[^/]*') // * matches anything except /
370
+ .replace(/\?/g, '[^/]') // ? matches single character except /
371
+ // Restore placeholders
372
+ .replace(/__GLOBSTAR_SLASH__/g, '(.*/)?') // **/ matches zero or more dirs
373
+ .replace(/__GLOBSTAR__/g, '.*') + // ** matches anything including /
374
+ '$');
375
+ }
376
+ /**
377
+ * Expand a glob pattern into concrete file paths.
378
+ *
379
+ * Used on Linux where bubblewrap doesn't support glob patterns natively.
380
+ * Resolves the static directory prefix, lists files recursively, and filters
381
+ * using globToRegex().
382
+ *
383
+ * @param globPath - A path pattern containing glob characters (e.g., ~/test/*.env)
384
+ * @returns Array of absolute paths matching the glob pattern
385
+ */
386
+ export function expandGlobPattern(globPath) {
387
+ const normalizedPattern = normalizePathForSandbox(globPath);
388
+ // Extract the static directory prefix before any glob characters
389
+ const staticPrefix = normalizedPattern.split(/[*?[\]]/)[0];
390
+ if (!staticPrefix || staticPrefix === '/') {
391
+ logForDebugging(`[Sandbox] Glob pattern too broad, skipping: ${globPath}`);
392
+ return [];
393
+ }
394
+ // Get the base directory from the static prefix
395
+ const baseDir = staticPrefix.endsWith('/')
396
+ ? staticPrefix.slice(0, -1)
397
+ : path.dirname(staticPrefix);
398
+ if (!fs.existsSync(baseDir)) {
399
+ logForDebugging(`[Sandbox] Base directory for glob does not exist: ${baseDir}`);
400
+ return [];
401
+ }
402
+ // Build regex from the normalized glob pattern
403
+ const regex = new RegExp(globToRegex(normalizedPattern));
404
+ // List all entries recursively under the base directory
405
+ const results = [];
406
+ try {
407
+ const entries = fs.readdirSync(baseDir, {
408
+ recursive: true,
409
+ withFileTypes: true,
410
+ });
411
+ for (const entry of entries) {
412
+ // Build the full path for this entry
413
+ // entry.parentPath is the directory containing this entry (available in Node 20+/Bun)
414
+ // For compatibility, fall back to entry.path if parentPath is not available
415
+ const parentDir = entry.parentPath ??
416
+ entry.path ??
417
+ baseDir;
418
+ const fullPath = path.join(parentDir, entry.name);
419
+ if (regex.test(fullPath)) {
420
+ results.push(fullPath);
421
+ }
422
+ }
423
+ }
424
+ catch (err) {
425
+ logForDebugging(`[Sandbox] Error expanding glob pattern ${globPath}: ${err}`);
426
+ }
427
+ return results;
428
+ }
429
+ //# sourceMappingURL=sandbox-utils.js.map