@anthropic-ai/sandbox-runtime 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +497 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +75 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/sandbox/http-proxy.d.ts +7 -0
- package/dist/sandbox/http-proxy.d.ts.map +1 -0
- package/dist/sandbox/http-proxy.js +118 -0
- package/dist/sandbox/http-proxy.js.map +1 -0
- package/dist/sandbox/linux-sandbox-utils.d.ts +60 -0
- package/dist/sandbox/linux-sandbox-utils.d.ts.map +1 -0
- package/dist/sandbox/linux-sandbox-utils.js +333 -0
- package/dist/sandbox/linux-sandbox-utils.js.map +1 -0
- package/dist/sandbox/macos-sandbox-utils.d.ts +53 -0
- package/dist/sandbox/macos-sandbox-utils.d.ts.map +1 -0
- package/dist/sandbox/macos-sandbox-utils.js +496 -0
- package/dist/sandbox/macos-sandbox-utils.js.map +1 -0
- package/dist/sandbox/sandbox-manager.d.ts +34 -0
- package/dist/sandbox/sandbox-manager.d.ts.map +1 -0
- package/dist/sandbox/sandbox-manager.js +655 -0
- package/dist/sandbox/sandbox-manager.js.map +1 -0
- package/dist/sandbox/sandbox-schemas.d.ts +93 -0
- package/dist/sandbox/sandbox-schemas.d.ts.map +1 -0
- package/dist/sandbox/sandbox-schemas.js +231 -0
- package/dist/sandbox/sandbox-schemas.js.map +1 -0
- package/dist/sandbox/sandbox-utils.d.ts +49 -0
- package/dist/sandbox/sandbox-utils.d.ts.map +1 -0
- package/dist/sandbox/sandbox-utils.js +345 -0
- package/dist/sandbox/sandbox-utils.js.map +1 -0
- package/dist/sandbox/sandbox-violation-store.d.ts +19 -0
- package/dist/sandbox/sandbox-violation-store.d.ts.map +1 -0
- package/dist/sandbox/sandbox-violation-store.js +54 -0
- package/dist/sandbox/sandbox-violation-store.js.map +1 -0
- package/dist/sandbox/socks-proxy.d.ts +13 -0
- package/dist/sandbox/socks-proxy.d.ts.map +1 -0
- package/dist/sandbox/socks-proxy.js +95 -0
- package/dist/sandbox/socks-proxy.js.map +1 -0
- package/dist/utils/debug.d.ts +7 -0
- package/dist/utils/debug.d.ts.map +1 -0
- package/dist/utils/debug.js +22 -0
- package/dist/utils/debug.js.map +1 -0
- package/dist/utils/exec.d.ts +13 -0
- package/dist/utils/exec.d.ts.map +1 -0
- package/dist/utils/exec.js +38 -0
- package/dist/utils/exec.js.map +1 -0
- package/dist/utils/platform.d.ts +6 -0
- package/dist/utils/platform.d.ts.map +1 -0
- package/dist/utils/platform.js +16 -0
- package/dist/utils/platform.js.map +1 -0
- package/dist/utils/ripgrep.d.ts +16 -0
- package/dist/utils/ripgrep.d.ts.map +1 -0
- package/dist/utils/ripgrep.js +57 -0
- package/dist/utils/ripgrep.js.map +1 -0
- package/dist/utils/settings.d.ts +147 -0
- package/dist/utils/settings.d.ts.map +1 -0
- package/dist/utils/settings.js +244 -0
- package/dist/utils/settings.js.map +1 -0
- package/package.json +72 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export interface FsReadRestrictionConfig {
|
|
3
|
+
denyOnly: string[];
|
|
4
|
+
}
|
|
5
|
+
export interface FsWriteRestrictionConfig {
|
|
6
|
+
allowOnly: string[];
|
|
7
|
+
denyWithinAllow: string[];
|
|
8
|
+
}
|
|
9
|
+
export interface NetworkRestrictionConfig {
|
|
10
|
+
allowedHosts?: string[];
|
|
11
|
+
deniedHosts?: string[];
|
|
12
|
+
}
|
|
13
|
+
export type NetworkHostPattern = {
|
|
14
|
+
host: string;
|
|
15
|
+
port: number | undefined;
|
|
16
|
+
};
|
|
17
|
+
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
|
+
//# 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":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAGvB,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;AAErB,wBAAgB,sBAAsB,CAAC,eAAe,EAAE,SAAS,GAAG,QAAQ,qEAiB3E;AAqKD;;;GAGG;AACH,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,MAAM,GACd,kBAAkB,GAAG,KAAK,CA2B5B;AAED;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,sBAAsB,2DAWhC,CAAA;AAEH,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,CAAA;AAO3E,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;GAiCnB,CAAA;AAGb,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAW9B,CAAA;AAEF,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAA"}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { isIP } from 'node:net';
|
|
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
|
+
});
|
|
231
|
+
//# 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,OAAO,EAAE,IAAI,EAAE,MAAM,UAAU,CAAA;AAC/B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AA2BvB,MAAM,UAAU,sBAAsB,CAAC,eAAqC;IAC1E,OAAO,CAAC;SACL,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;SACjB,QAAQ,CACP,yBAAyB,eAAe,8DAA8D,CACvG;SACA,SAAS,CAAC,CAAC,QAAQ,EAAY,EAAE;QAChC,uCAAuC;QACvC,OAAO,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE;YAC5B,MAAM,MAAM,GA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EAA+E;AAC/E,mBAAmB;AACnB,+EAA+E;AAE/E,8BAA8B;AAC9B,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC;KACjC,MAAM,CAAC;IACN,gBAAgB,EAAE,CAAC;SAChB,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;SACjB,QAAQ,EAAE;SACV,QAAQ,CACP,8IAA8I,CAC/I;IACH,iBAAiB,EAAE,CAAC;SACjB,OAAO,EAAE;SACT,QAAQ,EAAE;SACV,QAAQ,CACP,sGAAsG,CACvG;IACH,aAAa,EAAE,CAAC;SACb,MAAM,EAAE;SACR,GAAG,EAAE;SACL,GAAG,CAAC,CAAC,CAAC;SACN,GAAG,CAAC,KAAK,CAAC;SACV,QAAQ,EAAE;SACV,QAAQ,CACP,8GAA8G,CAC/G;IACH,cAAc,EAAE,CAAC;SACd,MAAM,EAAE;SACR,GAAG,EAAE;SACL,GAAG,CAAC,CAAC,CAAC;SACN,GAAG,CAAC,KAAK,CAAC;SACV,QAAQ,EAAE;SACV,QAAQ,CACP,+GAA+G,CAChH;CACJ,CAAC;KACD,QAAQ,EAAE,CAAA;AAEb,iCAAiC;AACjC,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1C,OAAO,EAAE,mBAAmB;IAC5B,gBAAgB,EAAE,sBAAsB,CAAC,QAAQ,EAAE;IACnD,yBAAyB,EAAE,CAAC;SACzB,OAAO,EAAE;SACT,QAAQ,EAAE;SACV,QAAQ,CACP,+FAA+F;QAC7F,8GAA8G;QAC9G,0BAA0B,CAC7B;CACJ,CAAC,CAAA"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if a path pattern contains glob characters
|
|
3
|
+
*/
|
|
4
|
+
export declare function containsGlobChars(pathPattern: string): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Remove trailing /** glob suffix from a path pattern
|
|
7
|
+
* Used to normalize path patterns since /** just means "directory and everything under it"
|
|
8
|
+
*/
|
|
9
|
+
export declare function removeTrailingGlobSuffix(pathPattern: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* Normalize a path for use in sandbox configurations
|
|
12
|
+
* Handles:
|
|
13
|
+
* - Tilde (~) expansion for home directory
|
|
14
|
+
* - Relative paths (./foo, ../foo, etc.) converted to absolute
|
|
15
|
+
* - Absolute paths remain unchanged
|
|
16
|
+
* - Symlinks are resolved to their real paths for non-glob patterns
|
|
17
|
+
* - Glob patterns preserve wildcards after path normalization
|
|
18
|
+
*
|
|
19
|
+
* Returns the absolute path with symlinks resolved (or normalized glob pattern)
|
|
20
|
+
*/
|
|
21
|
+
export declare function normalizePathForSandbox(pathPattern: string): string;
|
|
22
|
+
/**
|
|
23
|
+
* Get recommended system paths that should be writable for commands to work properly
|
|
24
|
+
*
|
|
25
|
+
* WARNING: These default paths are intentionally broad for compatibility but may
|
|
26
|
+
* allow access to files from other processes. In highly security-sensitive
|
|
27
|
+
* environments, you should configure more restrictive write paths.
|
|
28
|
+
*/
|
|
29
|
+
export declare function getDefaultWritePaths(): string[];
|
|
30
|
+
/**
|
|
31
|
+
* Get mandatory deny paths within allowed write areas
|
|
32
|
+
* This uses ripgrep to scan the filesystem for dangerous files and directories
|
|
33
|
+
* Returns absolute paths that must be blocked from writes
|
|
34
|
+
*/
|
|
35
|
+
export declare function getMandatoryDenyWithinAllow(): Promise<string[]>;
|
|
36
|
+
/**
|
|
37
|
+
* Generate proxy environment variables for sandboxed processes
|
|
38
|
+
*/
|
|
39
|
+
export declare function generateProxyEnvVars(httpProxyPort?: number, socksProxyPort?: number): string[];
|
|
40
|
+
/**
|
|
41
|
+
* Encode a command for sandbox monitoring
|
|
42
|
+
* Truncates to 100 chars and base64 encodes to avoid parsing issues
|
|
43
|
+
*/
|
|
44
|
+
export declare function encodeSandboxedCommand(command: string): string;
|
|
45
|
+
/**
|
|
46
|
+
* Decode a base64-encoded command from sandbox monitoring
|
|
47
|
+
*/
|
|
48
|
+
export declare function decodeSandboxedCommand(encodedCommand: string): string;
|
|
49
|
+
//# 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":"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,CA8BnE;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,IAAI,MAAM,EAAE,CAc/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"}
|