@anthropic-ai/sandbox-runtime 0.0.1 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +168 -88
- package/dist/cli.js +73 -8
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/sandbox/generate-seccomp-filter.d.ts +56 -0
- package/dist/sandbox/generate-seccomp-filter.d.ts.map +1 -0
- package/dist/sandbox/generate-seccomp-filter.js +158 -0
- package/dist/sandbox/generate-seccomp-filter.js.map +1 -0
- package/dist/sandbox/linux-sandbox-utils.d.ts +50 -3
- package/dist/sandbox/linux-sandbox-utils.d.ts.map +1 -1
- package/dist/sandbox/linux-sandbox-utils.js +267 -84
- package/dist/sandbox/linux-sandbox-utils.js.map +1 -1
- package/dist/sandbox/macos-sandbox-utils.d.ts +4 -1
- package/dist/sandbox/macos-sandbox-utils.d.ts.map +1 -1
- package/dist/sandbox/macos-sandbox-utils.js +89 -22
- package/dist/sandbox/macos-sandbox-utils.js.map +1 -1
- package/dist/sandbox/sandbox-config.d.ts +122 -0
- package/dist/sandbox/sandbox-config.d.ts.map +1 -0
- package/dist/sandbox/sandbox-config.js +75 -0
- package/dist/sandbox/sandbox-config.js.map +1 -0
- package/dist/sandbox/sandbox-manager.d.ts +4 -4
- package/dist/sandbox/sandbox-manager.d.ts.map +1 -1
- package/dist/sandbox/sandbox-manager.js +146 -237
- package/dist/sandbox/sandbox-manager.js.map +1 -1
- package/dist/sandbox/sandbox-schemas.d.ts +0 -76
- package/dist/sandbox/sandbox-schemas.d.ts.map +1 -1
- package/dist/sandbox/sandbox-schemas.js +1 -230
- package/dist/sandbox/sandbox-schemas.js.map +1 -1
- package/dist/sandbox/sandbox-utils.d.ts.map +1 -1
- package/dist/sandbox/sandbox-utils.js +25 -3
- package/dist/sandbox/sandbox-utils.js.map +1 -1
- package/dist/vendor/seccomp/arm64/apply-seccomp +0 -0
- package/dist/vendor/seccomp/arm64/unix-block.bpf +0 -0
- package/dist/vendor/seccomp/x64/apply-seccomp +0 -0
- package/dist/vendor/seccomp/x64/unix-block.bpf +0 -0
- package/dist/vendor/seccomp-src/apply-seccomp.c +98 -0
- package/dist/vendor/seccomp-src/seccomp-unix-block.c +97 -0
- package/package.json +10 -4
- package/vendor/seccomp/arm64/apply-seccomp +0 -0
- package/vendor/seccomp/arm64/unix-block.bpf +0 -0
- package/vendor/seccomp/x64/apply-seccomp +0 -0
- package/vendor/seccomp/x64/unix-block.bpf +0 -0
- package/vendor/seccomp-src/apply-seccomp.c +98 -0
- package/vendor/seccomp-src/seccomp-unix-block.c +97 -0
- package/dist/utils/exec.d.ts +0 -13
- package/dist/utils/exec.d.ts.map +0 -1
- package/dist/utils/exec.js +0 -38
- package/dist/utils/exec.js.map +0 -1
- package/dist/utils/settings.d.ts +0 -147
- package/dist/utils/settings.d.ts.map +0 -1
- package/dist/utils/settings.js +0 -244
- package/dist/utils/settings.js.map +0 -1
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
1
|
export interface FsReadRestrictionConfig {
|
|
3
2
|
denyOnly: string[];
|
|
4
3
|
}
|
|
@@ -15,79 +14,4 @@ export type NetworkHostPattern = {
|
|
|
15
14
|
port: number | undefined;
|
|
16
15
|
};
|
|
17
16
|
export type SandboxAskCallback = (params: NetworkHostPattern) => Promise<boolean>;
|
|
18
|
-
export declare function generateHostListSchema(allowedOrDenied: 'allowed' | 'denied'): z.ZodEffects<z.ZodArray<z.ZodString, "many">, string[], string[]>;
|
|
19
|
-
/**
|
|
20
|
-
* Safely parse a network restriction pattern.
|
|
21
|
-
* Returns the parsed pattern or an Error.
|
|
22
|
-
*/
|
|
23
|
-
export declare function safeParseRestrictionPattern(pattern: string): NetworkHostPattern | Error;
|
|
24
|
-
/**
|
|
25
|
-
* Schema for command-specific sandbox violation ignore patterns.
|
|
26
|
-
* Maps command patterns to lists of filesystem paths to ignore violations for.
|
|
27
|
-
* The special key "*" matches all commands.
|
|
28
|
-
*
|
|
29
|
-
* Example:
|
|
30
|
-
* {
|
|
31
|
-
* "*": ["/usr/bin", "/System"], // Ignore for all commands
|
|
32
|
-
* "git push": ["/usr/bin/nc"], // Ignore nc errors when running git push
|
|
33
|
-
* "npm": ["/private/tmp"], // Ignore tmp access for npm commands
|
|
34
|
-
* }
|
|
35
|
-
*/
|
|
36
|
-
export declare const IgnoreViolationsSchema: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString, "many">>;
|
|
37
|
-
export type IgnoreViolationsConfig = z.infer<typeof IgnoreViolationsSchema>;
|
|
38
|
-
export declare const NetworkConfigSchema: z.ZodOptional<z.ZodObject<{
|
|
39
|
-
allowUnixSockets: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
40
|
-
allowLocalBinding: z.ZodOptional<z.ZodBoolean>;
|
|
41
|
-
httpProxyPort: z.ZodOptional<z.ZodNumber>;
|
|
42
|
-
socksProxyPort: z.ZodOptional<z.ZodNumber>;
|
|
43
|
-
}, "strip", z.ZodTypeAny, {
|
|
44
|
-
allowUnixSockets?: string[] | undefined;
|
|
45
|
-
allowLocalBinding?: boolean | undefined;
|
|
46
|
-
httpProxyPort?: number | undefined;
|
|
47
|
-
socksProxyPort?: number | undefined;
|
|
48
|
-
}, {
|
|
49
|
-
allowUnixSockets?: string[] | undefined;
|
|
50
|
-
allowLocalBinding?: boolean | undefined;
|
|
51
|
-
httpProxyPort?: number | undefined;
|
|
52
|
-
socksProxyPort?: number | undefined;
|
|
53
|
-
}>>;
|
|
54
|
-
export declare const SandboxConfigSchema: z.ZodObject<{
|
|
55
|
-
network: z.ZodOptional<z.ZodObject<{
|
|
56
|
-
allowUnixSockets: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
57
|
-
allowLocalBinding: z.ZodOptional<z.ZodBoolean>;
|
|
58
|
-
httpProxyPort: z.ZodOptional<z.ZodNumber>;
|
|
59
|
-
socksProxyPort: z.ZodOptional<z.ZodNumber>;
|
|
60
|
-
}, "strip", z.ZodTypeAny, {
|
|
61
|
-
allowUnixSockets?: string[] | undefined;
|
|
62
|
-
allowLocalBinding?: boolean | undefined;
|
|
63
|
-
httpProxyPort?: number | undefined;
|
|
64
|
-
socksProxyPort?: number | undefined;
|
|
65
|
-
}, {
|
|
66
|
-
allowUnixSockets?: string[] | undefined;
|
|
67
|
-
allowLocalBinding?: boolean | undefined;
|
|
68
|
-
httpProxyPort?: number | undefined;
|
|
69
|
-
socksProxyPort?: number | undefined;
|
|
70
|
-
}>>;
|
|
71
|
-
ignoreViolations: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString, "many">>>;
|
|
72
|
-
enableWeakerNestedSandbox: z.ZodOptional<z.ZodBoolean>;
|
|
73
|
-
}, "strip", z.ZodTypeAny, {
|
|
74
|
-
network?: {
|
|
75
|
-
allowUnixSockets?: string[] | undefined;
|
|
76
|
-
allowLocalBinding?: boolean | undefined;
|
|
77
|
-
httpProxyPort?: number | undefined;
|
|
78
|
-
socksProxyPort?: number | undefined;
|
|
79
|
-
} | undefined;
|
|
80
|
-
ignoreViolations?: Record<string, string[]> | undefined;
|
|
81
|
-
enableWeakerNestedSandbox?: boolean | undefined;
|
|
82
|
-
}, {
|
|
83
|
-
network?: {
|
|
84
|
-
allowUnixSockets?: string[] | undefined;
|
|
85
|
-
allowLocalBinding?: boolean | undefined;
|
|
86
|
-
httpProxyPort?: number | undefined;
|
|
87
|
-
socksProxyPort?: number | undefined;
|
|
88
|
-
} | undefined;
|
|
89
|
-
ignoreViolations?: Record<string, string[]> | undefined;
|
|
90
|
-
enableWeakerNestedSandbox?: boolean | undefined;
|
|
91
|
-
}>;
|
|
92
|
-
export type SandboxConfig = z.infer<typeof SandboxConfigSchema>;
|
|
93
17
|
//# sourceMappingURL=sandbox-schemas.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sandbox-schemas.d.ts","sourceRoot":"","sources":["../../src/sandbox/sandbox-schemas.ts"],"names":[],"mappings":"AACA,
|
|
1
|
+
{"version":3,"file":"sandbox-schemas.d.ts","sourceRoot":"","sources":["../../src/sandbox/sandbox-schemas.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,uBAAuB;IACtC,QAAQ,EAAE,MAAM,EAAE,CAAA;CACnB;AAED,MAAM,WAAW,wBAAwB;IACvC,SAAS,EAAE,MAAM,EAAE,CAAA;IACnB,eAAe,EAAE,MAAM,EAAE,CAAA;CAC1B;AAGD,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"}
|
|
@@ -1,231 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
export function generateHostListSchema(allowedOrDenied) {
|
|
4
|
-
return z
|
|
5
|
-
.array(z.string())
|
|
6
|
-
.describe(`List of automatically ${allowedOrDenied} network hosts (e.g., ["github.com:443", "api.example.com"])`)
|
|
7
|
-
.transform((patterns) => {
|
|
8
|
-
// Parse and validate each host pattern
|
|
9
|
-
return patterns.map(pattern => {
|
|
10
|
-
const parsed = safeParseRestrictionPattern(pattern);
|
|
11
|
-
if (parsed instanceof Error) {
|
|
12
|
-
throw new Error(`Invalid network host pattern: ${parsed.message}`);
|
|
13
|
-
}
|
|
14
|
-
// Return the original validated string, not the parsed pattern
|
|
15
|
-
return pattern;
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
// Port number schema
|
|
20
|
-
const portNumberSchema = z
|
|
21
|
-
.string()
|
|
22
|
-
.regex(/^\d+$/)
|
|
23
|
-
.transform(val => parseInt(val, 10))
|
|
24
|
-
.refine(port => port >= 1 && port <= 65535, 'Port must be between 1 and 65535');
|
|
25
|
-
// Schema for IPv6 addresses without port
|
|
26
|
-
// Examples: "::1" (IPv6 loopback), "2001:db8::1", "fe80::1"
|
|
27
|
-
const ipv6Schema = z
|
|
28
|
-
.string()
|
|
29
|
-
.refine(val => isIP(val) === 6 && !val.includes('[') && !val.includes(']'))
|
|
30
|
-
.transform((val) => ({
|
|
31
|
-
host: val,
|
|
32
|
-
port: undefined,
|
|
33
|
-
}));
|
|
34
|
-
// Schema for IPv6 addresses with port (requires bracket notation)
|
|
35
|
-
// Examples: "[::1]:8080", "[2001:db8::1]:443", "[fe80::1]:22"
|
|
36
|
-
const ipv6WithPortSchema = z
|
|
37
|
-
.string()
|
|
38
|
-
.regex(/^\[([^\]]+)\]:(\d+)$/)
|
|
39
|
-
.transform((val) => {
|
|
40
|
-
const match = val.match(/^\[([^\]]+)\]:(\d+)$/);
|
|
41
|
-
const host = match[1];
|
|
42
|
-
const portStr = match[2];
|
|
43
|
-
// Validate that the host part is actually an IPv6 address
|
|
44
|
-
if (isIP(host) !== 6) {
|
|
45
|
-
throw new Error('Invalid IPv6 address in bracket notation');
|
|
46
|
-
}
|
|
47
|
-
// Parse and validate port
|
|
48
|
-
const portResult = portNumberSchema.safeParse(portStr);
|
|
49
|
-
if (!portResult.success) {
|
|
50
|
-
throw new Error('Invalid port number');
|
|
51
|
-
}
|
|
52
|
-
const port = portResult.data;
|
|
53
|
-
return { host, port };
|
|
54
|
-
});
|
|
55
|
-
// Schema for IPv4 addresses without port
|
|
56
|
-
// Examples: "192.168.1.1", "127.0.0.1", "10.0.0.1"
|
|
57
|
-
const ipv4Schema = z
|
|
58
|
-
.string()
|
|
59
|
-
.refine(val => isIP(val) === 4)
|
|
60
|
-
.transform((val) => ({
|
|
61
|
-
host: val,
|
|
62
|
-
port: undefined,
|
|
63
|
-
}));
|
|
64
|
-
// Schema for IPv4 addresses with port
|
|
65
|
-
// Examples: "192.168.1.1:8080", "127.0.0.1:443", "10.0.0.1:22"
|
|
66
|
-
const ipv4WithPortSchema = z
|
|
67
|
-
.string()
|
|
68
|
-
.regex(/^(\d+\.\d+\.\d+\.\d+):(\d+)$/)
|
|
69
|
-
.transform((val) => {
|
|
70
|
-
const match = val.match(/^(\d+\.\d+\.\d+\.\d+):(\d+)$/);
|
|
71
|
-
const host = match[1];
|
|
72
|
-
const portStr = match[2];
|
|
73
|
-
// Validate that the host part is actually an IPv4 address
|
|
74
|
-
if (isIP(host) !== 4) {
|
|
75
|
-
throw new Error('Invalid IPv4 address format');
|
|
76
|
-
}
|
|
77
|
-
// Parse and validate port
|
|
78
|
-
const portResult = portNumberSchema.safeParse(portStr);
|
|
79
|
-
if (!portResult.success) {
|
|
80
|
-
throw new Error('Invalid port number');
|
|
81
|
-
}
|
|
82
|
-
const port = portResult.data;
|
|
83
|
-
return { host, port };
|
|
84
|
-
});
|
|
85
|
-
// Base schema for validating domain names (not IP addresses)
|
|
86
|
-
// Examples: "example.com", "localhost", "*.example.com", "sub.domain.com"
|
|
87
|
-
const domainNameSchema = z.string().refine(val => {
|
|
88
|
-
// Basic format checks
|
|
89
|
-
if (val.length === 0 ||
|
|
90
|
-
val.includes(':') || // No colons (would indicate port or IPv6)
|
|
91
|
-
val.includes('/') || // No paths or protocol prefixes
|
|
92
|
-
val.includes('?') || // No query strings
|
|
93
|
-
val.includes('#') || // No fragments
|
|
94
|
-
isIP(val) // Not an IP address
|
|
95
|
-
) {
|
|
96
|
-
return false;
|
|
97
|
-
}
|
|
98
|
-
// Special case: localhost is always valid
|
|
99
|
-
if (val === 'localhost') {
|
|
100
|
-
return true;
|
|
101
|
-
}
|
|
102
|
-
// Wildcard domains: *.example.com (must have dot after wildcard)
|
|
103
|
-
if (val.startsWith('*.')) {
|
|
104
|
-
const domainPart = val.slice(2);
|
|
105
|
-
return (domainPart.includes('.') &&
|
|
106
|
-
!domainPart.startsWith('.') &&
|
|
107
|
-
!domainPart.endsWith('.'));
|
|
108
|
-
}
|
|
109
|
-
// Regular domains: must contain at least one dot and not start/end with dot
|
|
110
|
-
return val.includes('.') && !val.startsWith('.') && !val.endsWith('.');
|
|
111
|
-
});
|
|
112
|
-
// Schema for domain name without port
|
|
113
|
-
// Examples: "example.com", "*.example.com", "localhost"
|
|
114
|
-
const hostnameSchema = domainNameSchema.transform((val) => ({
|
|
115
|
-
host: val,
|
|
116
|
-
port: undefined,
|
|
117
|
-
}));
|
|
118
|
-
// Schema for domain name with port
|
|
119
|
-
// Examples: "example.com:8080", "localhost:3000", "*.example.com:443"
|
|
120
|
-
const hostnameWithPortSchema = z
|
|
121
|
-
.string()
|
|
122
|
-
.regex(/^([^:]+):(\d+)$/)
|
|
123
|
-
.transform((val) => {
|
|
124
|
-
const match = val.match(/^([^:]+):(\d+)$/);
|
|
125
|
-
const host = match[1];
|
|
126
|
-
const portStr = match[2];
|
|
127
|
-
// Validate that the host part is a valid domain name
|
|
128
|
-
const hostResult = domainNameSchema.safeParse(host);
|
|
129
|
-
if (!hostResult.success) {
|
|
130
|
-
throw new Error('Invalid domain name');
|
|
131
|
-
}
|
|
132
|
-
// Parse and validate port
|
|
133
|
-
const portResult = portNumberSchema.safeParse(portStr);
|
|
134
|
-
if (!portResult.success) {
|
|
135
|
-
throw new Error('Invalid port number');
|
|
136
|
-
}
|
|
137
|
-
const port = portResult.data;
|
|
138
|
-
return { host, port };
|
|
139
|
-
});
|
|
140
|
-
// Combined schema that tries each pattern in order
|
|
141
|
-
const hostPatternSchema = z.union([
|
|
142
|
-
ipv6WithPortSchema,
|
|
143
|
-
ipv6Schema,
|
|
144
|
-
ipv4WithPortSchema,
|
|
145
|
-
ipv4Schema,
|
|
146
|
-
hostnameWithPortSchema,
|
|
147
|
-
hostnameSchema,
|
|
148
|
-
]);
|
|
149
|
-
/**
|
|
150
|
-
* Safely parse a network restriction pattern.
|
|
151
|
-
* Returns the parsed pattern or an Error.
|
|
152
|
-
*/
|
|
153
|
-
export function safeParseRestrictionPattern(pattern) {
|
|
154
|
-
const result = hostPatternSchema.safeParse(pattern);
|
|
155
|
-
if (!result.success) {
|
|
156
|
-
// Provide helpful error messages for common mistakes
|
|
157
|
-
if (pattern.startsWith('http://') || pattern.startsWith('https://')) {
|
|
158
|
-
return Error(`Invalid network restriction: "${pattern}" - remove the protocol (http:// or https://)`);
|
|
159
|
-
}
|
|
160
|
-
if (pattern.includes('/')) {
|
|
161
|
-
return Error(`Invalid network restriction: "${pattern}" - paths are not allowed, only hosts`);
|
|
162
|
-
}
|
|
163
|
-
if (pattern === '') {
|
|
164
|
-
return Error(`Invalid network restriction: empty string - please provide a host`);
|
|
165
|
-
}
|
|
166
|
-
if (pattern.endsWith(':')) {
|
|
167
|
-
return Error(`Invalid network restriction: "${pattern}" - incomplete port specification`);
|
|
168
|
-
}
|
|
169
|
-
return Error(`Invalid network restriction: "${pattern}"`);
|
|
170
|
-
}
|
|
171
|
-
return result.data;
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Schema for command-specific sandbox violation ignore patterns.
|
|
175
|
-
* Maps command patterns to lists of filesystem paths to ignore violations for.
|
|
176
|
-
* The special key "*" matches all commands.
|
|
177
|
-
*
|
|
178
|
-
* Example:
|
|
179
|
-
* {
|
|
180
|
-
* "*": ["/usr/bin", "/System"], // Ignore for all commands
|
|
181
|
-
* "git push": ["/usr/bin/nc"], // Ignore nc errors when running git push
|
|
182
|
-
* "npm": ["/private/tmp"], // Ignore tmp access for npm commands
|
|
183
|
-
* }
|
|
184
|
-
*/
|
|
185
|
-
export const IgnoreViolationsSchema = z
|
|
186
|
-
.record(z.string(), z
|
|
187
|
-
.array(z.string())
|
|
188
|
-
.describe('List of filesystem paths to ignore sandbox violations for when this command pattern matches'))
|
|
189
|
-
.describe('Map of command patterns to filesystem paths to ignore violations for. Use "*" to match all commands');
|
|
190
|
-
// ============================================================================
|
|
191
|
-
// COMBINED SCHEMAS
|
|
192
|
-
// ============================================================================
|
|
193
|
-
// Network restriction schemas
|
|
194
|
-
export const NetworkConfigSchema = z
|
|
195
|
-
.object({
|
|
196
|
-
allowUnixSockets: z
|
|
197
|
-
.array(z.string())
|
|
198
|
-
.optional()
|
|
199
|
-
.describe('Allow Unix domain sockets for local IPC (SSH agent, Docker, etc.). Provide an array of specific paths. Defaults to blocking if not specified'),
|
|
200
|
-
allowLocalBinding: z
|
|
201
|
-
.boolean()
|
|
202
|
-
.optional()
|
|
203
|
-
.describe('Allow binding to local network addresses (e.g., localhost ports). Defaults to false if not specified'),
|
|
204
|
-
httpProxyPort: z
|
|
205
|
-
.number()
|
|
206
|
-
.int()
|
|
207
|
-
.min(1)
|
|
208
|
-
.max(65535)
|
|
209
|
-
.optional()
|
|
210
|
-
.describe('HTTP proxy port to use for network filtering. If not specified, a proxy server will be started automatically'),
|
|
211
|
-
socksProxyPort: z
|
|
212
|
-
.number()
|
|
213
|
-
.int()
|
|
214
|
-
.min(1)
|
|
215
|
-
.max(65535)
|
|
216
|
-
.optional()
|
|
217
|
-
.describe('SOCKS proxy port to use for network filtering. If not specified, a proxy server will be started automatically'),
|
|
218
|
-
})
|
|
219
|
-
.optional();
|
|
220
|
-
// Complete sandbox config schema
|
|
221
|
-
export const SandboxConfigSchema = z.object({
|
|
222
|
-
network: NetworkConfigSchema,
|
|
223
|
-
ignoreViolations: IgnoreViolationsSchema.optional(),
|
|
224
|
-
enableWeakerNestedSandbox: z
|
|
225
|
-
.boolean()
|
|
226
|
-
.optional()
|
|
227
|
-
.describe('Enable weaker sandbox mode for unprivileged docker environments where --proc mounting fails. ' +
|
|
228
|
-
'This significantly reduces the strength of the sandbox and should only be used when this risk is acceptable.' +
|
|
229
|
-
'Default: false (secure).'),
|
|
230
|
-
});
|
|
1
|
+
export {};
|
|
231
2
|
//# sourceMappingURL=sandbox-schemas.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sandbox-schemas.js","sourceRoot":"","sources":["../../src/sandbox/sandbox-schemas.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sandbox-schemas.js","sourceRoot":"","sources":["../../src/sandbox/sandbox-schemas.ts"],"names":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sandbox-utils.d.ts","sourceRoot":"","sources":["../../src/sandbox/sandbox-utils.ts"],"names":[],"mappings":"AAyCA;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAO9D;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAEpE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"sandbox-utils.d.ts","sourceRoot":"","sources":["../../src/sandbox/sandbox-utils.ts"],"names":[],"mappings":"AAyCA;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAO9D;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAEpE;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAiDnE;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,EAAE,CAiB/C;AAED;;;;GAIG;AACH,wBAAsB,2BAA2B,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAqKrE;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,aAAa,CAAC,EAAE,MAAM,EACtB,cAAc,CAAC,EAAE,MAAM,GACtB,MAAM,EAAE,CA6FV;AAED;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAG9D;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,cAAc,EAAE,MAAM,GAAG,MAAM,CAErE"}
|
|
@@ -80,8 +80,27 @@ export function normalizePathForSandbox(pathPattern) {
|
|
|
80
80
|
// Handle other relative paths (e.g., ".", "..", "foo/bar")
|
|
81
81
|
normalizedPath = path.resolve(cwd, pathPattern);
|
|
82
82
|
}
|
|
83
|
-
// For glob patterns,
|
|
83
|
+
// For glob patterns, resolve symlinks for the directory portion only
|
|
84
84
|
if (containsGlobChars(normalizedPath)) {
|
|
85
|
+
// Extract the static directory prefix before glob characters
|
|
86
|
+
const staticPrefix = normalizedPath.split(/[*?\[\]]/)[0];
|
|
87
|
+
if (staticPrefix && staticPrefix !== '/') {
|
|
88
|
+
// Get the directory containing the glob pattern
|
|
89
|
+
// If staticPrefix ends with /, remove it to get the directory
|
|
90
|
+
const baseDir = staticPrefix.endsWith('/')
|
|
91
|
+
? staticPrefix.slice(0, -1)
|
|
92
|
+
: path.dirname(staticPrefix);
|
|
93
|
+
// Try to resolve symlinks for the base directory
|
|
94
|
+
try {
|
|
95
|
+
const resolvedBaseDir = fs.realpathSync(baseDir);
|
|
96
|
+
// Reconstruct the pattern with the resolved directory
|
|
97
|
+
const patternSuffix = normalizedPath.slice(baseDir.length);
|
|
98
|
+
return resolvedBaseDir + patternSuffix;
|
|
99
|
+
}
|
|
100
|
+
catch {
|
|
101
|
+
// If directory doesn't exist or can't be resolved, keep the original pattern
|
|
102
|
+
}
|
|
103
|
+
}
|
|
85
104
|
return normalizedPath;
|
|
86
105
|
}
|
|
87
106
|
// Resolve symlinks to real paths to avoid bwrap issues
|
|
@@ -109,7 +128,10 @@ export function getDefaultWritePaths() {
|
|
|
109
128
|
'/dev/tty',
|
|
110
129
|
'/dev/dtracehelper',
|
|
111
130
|
'/dev/autofs_nowait',
|
|
131
|
+
'/tmp/claude',
|
|
132
|
+
'/private/tmp/claude',
|
|
112
133
|
path.join(homeDir, '.npm/_logs'),
|
|
134
|
+
path.join(homeDir, '.claude/debug'),
|
|
113
135
|
'.',
|
|
114
136
|
];
|
|
115
137
|
return recommendedPaths;
|
|
@@ -258,8 +280,8 @@ export async function getMandatoryDenyWithinAllow() {
|
|
|
258
280
|
* Generate proxy environment variables for sandboxed processes
|
|
259
281
|
*/
|
|
260
282
|
export function generateProxyEnvVars(httpProxyPort, socksProxyPort) {
|
|
261
|
-
const envVars = [`SANDBOX_RUNTIME=1`];
|
|
262
|
-
// If no proxy ports provided, return
|
|
283
|
+
const envVars = [`SANDBOX_RUNTIME=1`, `TMPDIR=/tmp/claude`];
|
|
284
|
+
// If no proxy ports provided, return minimal env vars
|
|
263
285
|
if (!httpProxyPort && !socksProxyPort) {
|
|
264
286
|
return envVars;
|
|
265
287
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sandbox-utils.js","sourceRoot":"","sources":["../../src/sandbox/sandbox-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAA;AAC5B,OAAO,KAAK,IAAI,MAAM,MAAM,CAAA;AAC5B,OAAO,KAAK,EAAE,MAAM,IAAI,CAAA;AACxB,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAE7C;;;GAGG;AACH,MAAM,eAAe,GAAG;IACtB,YAAY;IACZ,aAAa;IACb,SAAS;IACT,eAAe;IACf,QAAQ;IACR,WAAW;IACX,UAAU;IACV,YAAY;IACZ,WAAW;CACH,CAAA;AAEV;;;GAGG;AACH,MAAM,qBAAqB,GAAG,CAAC,MAAM,EAAE,SAAS,EAAE,OAAO,CAAU,CAAA;AAEnE;;;;;;;;GAQG;AACH,SAAS,0BAA0B,CAAC,OAAe;IACjD,OAAO,OAAO,CAAC,WAAW,EAAE,CAAA;AAC9B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,WAAmB;IACnD,OAAO,CACL,WAA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C,OAAO,CAAC,IAAI,CAAC,kCAAkC,cAAc,EAAE,CAAC,CAAA;QAChE,OAAO,CAAC,IAAI,CAAC,kCAAkC,cAAc,EAAE,CAAC,CAAA;IAClE,CAAC;IAED,8FAA8F;IAC9F,4FAA4F;IAC5F,mGAAmG;IAEnG,OAAO,OAAO,CAAA;AAChB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,sBAAsB,CAAC,OAAe;IACpD,MAAM,gBAAgB,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;IAC9C,OAAO,MAAM,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;AACzD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,sBAAsB,CAAC,cAAsB;IAC3D,OAAO,MAAM,CAAC,IAAI,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAA;AAC/D,CAAC"}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* apply-seccomp.c - Apply seccomp BPF filter and exec command
|
|
3
|
+
*
|
|
4
|
+
* Usage: apply-seccomp <filter.bpf> <command> [args...]
|
|
5
|
+
*
|
|
6
|
+
* This program reads a pre-compiled BPF filter from a file, applies it
|
|
7
|
+
* using prctl(PR_SET_SECCOMP), and then execs the specified command.
|
|
8
|
+
*
|
|
9
|
+
* The BPF filter must be in the format expected by SECCOMP_MODE_FILTER:
|
|
10
|
+
* - struct sock_fprog { unsigned short len; struct sock_filter *filter; }
|
|
11
|
+
* - Each filter instruction is 8 bytes (BPF instruction format)
|
|
12
|
+
*
|
|
13
|
+
* Compile: gcc -static -O2 -o apply-seccomp apply-seccomp.c
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
#include <stdio.h>
|
|
17
|
+
#include <stdlib.h>
|
|
18
|
+
#include <string.h>
|
|
19
|
+
#include <unistd.h>
|
|
20
|
+
#include <fcntl.h>
|
|
21
|
+
#include <sys/prctl.h>
|
|
22
|
+
#include <linux/seccomp.h>
|
|
23
|
+
#include <linux/filter.h>
|
|
24
|
+
#include <errno.h>
|
|
25
|
+
|
|
26
|
+
#ifndef PR_SET_NO_NEW_PRIVS
|
|
27
|
+
#define PR_SET_NO_NEW_PRIVS 38
|
|
28
|
+
#endif
|
|
29
|
+
|
|
30
|
+
#ifndef SECCOMP_MODE_FILTER
|
|
31
|
+
#define SECCOMP_MODE_FILTER 2
|
|
32
|
+
#endif
|
|
33
|
+
|
|
34
|
+
#define MAX_FILTER_SIZE 4096 // Maximum BPF filter size in bytes
|
|
35
|
+
|
|
36
|
+
int main(int argc, char *argv[], char *envp[]) {
|
|
37
|
+
if (argc < 3) {
|
|
38
|
+
fprintf(stderr, "Usage: %s <filter.bpf> <command> [args...]\n", argv[0]);
|
|
39
|
+
return 1;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const char *filter_path = argv[1];
|
|
43
|
+
char **command_argv = &argv[2];
|
|
44
|
+
|
|
45
|
+
// Open and read BPF filter file
|
|
46
|
+
int fd = open(filter_path, O_RDONLY);
|
|
47
|
+
if (fd < 0) {
|
|
48
|
+
perror("Failed to open BPF filter file");
|
|
49
|
+
return 1;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Read filter into memory
|
|
53
|
+
unsigned char filter_bytes[MAX_FILTER_SIZE];
|
|
54
|
+
ssize_t filter_size = read(fd, filter_bytes, MAX_FILTER_SIZE);
|
|
55
|
+
close(fd);
|
|
56
|
+
|
|
57
|
+
if (filter_size < 0) {
|
|
58
|
+
perror("Failed to read BPF filter");
|
|
59
|
+
return 1;
|
|
60
|
+
}
|
|
61
|
+
if (filter_size == 0) {
|
|
62
|
+
fprintf(stderr, "BPF filter file is empty\n");
|
|
63
|
+
return 1;
|
|
64
|
+
}
|
|
65
|
+
if (filter_size % 8 != 0) {
|
|
66
|
+
fprintf(stderr, "Invalid BPF filter size: %zd (must be multiple of 8)\n", filter_size);
|
|
67
|
+
return 1;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Convert bytes to sock_filter instructions
|
|
71
|
+
unsigned short filter_len = filter_size / 8;
|
|
72
|
+
struct sock_filter *filter = (struct sock_filter *)filter_bytes;
|
|
73
|
+
|
|
74
|
+
// Set up sock_fprog structure
|
|
75
|
+
struct sock_fprog prog = {
|
|
76
|
+
.len = filter_len,
|
|
77
|
+
.filter = filter,
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
// Set NO_NEW_PRIVS to allow seccomp without CAP_SYS_ADMIN
|
|
81
|
+
if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) != 0) {
|
|
82
|
+
perror("prctl(PR_SET_NO_NEW_PRIVS) failed");
|
|
83
|
+
return 1;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Apply seccomp filter
|
|
87
|
+
if (prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog) != 0) {
|
|
88
|
+
perror("prctl(PR_SET_SECCOMP) failed");
|
|
89
|
+
return 1;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Exec the command with seccomp filter active
|
|
93
|
+
execvp(command_argv[0], command_argv);
|
|
94
|
+
|
|
95
|
+
// If we get here, exec failed
|
|
96
|
+
perror("execvp failed");
|
|
97
|
+
return 1;
|
|
98
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Seccomp BPF filter generator to block Unix domain socket creation
|
|
3
|
+
*
|
|
4
|
+
* This program generates a seccomp-bpf filter that blocks the socket() syscall
|
|
5
|
+
* when called with AF_UNIX as the domain argument. This prevents creation of
|
|
6
|
+
* Unix domain sockets while allowing all other socket types (AF_INET, AF_INET6, etc.)
|
|
7
|
+
* and all other syscalls.
|
|
8
|
+
*
|
|
9
|
+
* The filter is exported in a format compatible with bubblewrap's --seccomp flag.
|
|
10
|
+
*
|
|
11
|
+
* SECURITY LIMITATION - 32-bit x86 (ia32):
|
|
12
|
+
* TODO: This filter does NOT block socketcall() syscall, which is a security issue
|
|
13
|
+
* on 32-bit x86 systems. On ia32, the socket() syscall doesn't exist - instead,
|
|
14
|
+
* all socket operations are multiplexed through socketcall():
|
|
15
|
+
* - socketcall(SYS_SOCKET, [AF_UNIX, ...]) - can bypass this filter
|
|
16
|
+
* - socketcall(SYS_SOCKETPAIR, [AF_UNIX, ...]) - can bypass this filter
|
|
17
|
+
*
|
|
18
|
+
* To fix this, we need to add conditional rules that:
|
|
19
|
+
* 1. Check if socketcall() exists on the current architecture (32-bit x86 only)
|
|
20
|
+
* 2. Block socketcall(SYS_SOCKET, ...) when first arg of sub-call is AF_UNIX
|
|
21
|
+
* 3. Block socketcall(SYS_SOCKETPAIR, ...) when first arg of sub-call is AF_UNIX
|
|
22
|
+
*
|
|
23
|
+
* This requires inspecting the arguments passed to socketcall, which is more
|
|
24
|
+
* complex BPF logic. For now, 32-bit x86 is not supported.
|
|
25
|
+
*
|
|
26
|
+
* Compilation:
|
|
27
|
+
* gcc -o seccomp-unix-block seccomp-unix-block.c -lseccomp
|
|
28
|
+
*
|
|
29
|
+
* Usage:
|
|
30
|
+
* ./seccomp-unix-block <output-file>
|
|
31
|
+
*
|
|
32
|
+
* Dependencies:
|
|
33
|
+
* - libseccomp (libseccomp-dev package on Debian/Ubuntu)
|
|
34
|
+
*/
|
|
35
|
+
|
|
36
|
+
#include <errno.h>
|
|
37
|
+
#include <fcntl.h>
|
|
38
|
+
#include <stdio.h>
|
|
39
|
+
#include <stdlib.h>
|
|
40
|
+
#include <string.h>
|
|
41
|
+
#include <unistd.h>
|
|
42
|
+
#include <seccomp.h>
|
|
43
|
+
#include <sys/socket.h>
|
|
44
|
+
#include <sys/stat.h>
|
|
45
|
+
#include <sys/types.h>
|
|
46
|
+
|
|
47
|
+
int main(int argc, char *argv[]) {
|
|
48
|
+
scmp_filter_ctx ctx;
|
|
49
|
+
int rc;
|
|
50
|
+
|
|
51
|
+
if (argc != 2) {
|
|
52
|
+
fprintf(stderr, "Usage: %s <output-file>\n", argv[0]);
|
|
53
|
+
return 1;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const char *output_file = argv[1];
|
|
57
|
+
|
|
58
|
+
/* Create seccomp context with default action ALLOW */
|
|
59
|
+
ctx = seccomp_init(SCMP_ACT_ALLOW);
|
|
60
|
+
if (ctx == NULL) {
|
|
61
|
+
fprintf(stderr, "Error: Failed to initialize seccomp context\n");
|
|
62
|
+
return 1;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/* Add rule to block socket(AF_UNIX, ...) */
|
|
66
|
+
/* socket() syscall signature: int socket(int domain, int type, int protocol) */
|
|
67
|
+
/* arg0 = domain (AF_UNIX = 1) */
|
|
68
|
+
rc = seccomp_rule_add(ctx, SCMP_ACT_ERRNO(EPERM), SCMP_SYS(socket), 1,
|
|
69
|
+
SCMP_A0(SCMP_CMP_EQ, AF_UNIX));
|
|
70
|
+
if (rc < 0) {
|
|
71
|
+
fprintf(stderr, "Error: Failed to add seccomp rule: %s\n", strerror(-rc));
|
|
72
|
+
seccomp_release(ctx);
|
|
73
|
+
return 1;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/* Export the filter to a file */
|
|
77
|
+
int fd = open(output_file, O_CREAT | O_WRONLY | O_TRUNC, 0600);
|
|
78
|
+
if (fd < 0) {
|
|
79
|
+
fprintf(stderr, "Error: Failed to open output file: %s\n", strerror(errno));
|
|
80
|
+
seccomp_release(ctx);
|
|
81
|
+
return 1;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
rc = seccomp_export_bpf(ctx, fd);
|
|
85
|
+
if (rc < 0) {
|
|
86
|
+
fprintf(stderr, "Error: Failed to export seccomp filter: %s\n", strerror(-rc));
|
|
87
|
+
close(fd);
|
|
88
|
+
seccomp_release(ctx);
|
|
89
|
+
return 1;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/* Clean up */
|
|
93
|
+
close(fd);
|
|
94
|
+
seccomp_release(ctx);
|
|
95
|
+
|
|
96
|
+
return 0;
|
|
97
|
+
}
|