@cloudflare/sandbox 0.3.6 → 0.4.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/.turbo/turbo-build.log +44 -0
- package/CHANGELOG.md +6 -8
- package/Dockerfile +88 -18
- package/README.md +89 -824
- package/dist/{chunk-JTKON2SH.js → chunk-BCJ7SF3Q.js} +9 -5
- package/dist/chunk-BCJ7SF3Q.js.map +1 -0
- package/dist/chunk-BFVUNTP4.js +104 -0
- package/dist/chunk-BFVUNTP4.js.map +1 -0
- package/dist/{chunk-NNGBXDMY.js → chunk-EKSWCBCA.js} +3 -6
- package/dist/chunk-EKSWCBCA.js.map +1 -0
- package/dist/chunk-HGF554LH.js +2236 -0
- package/dist/chunk-HGF554LH.js.map +1 -0
- package/dist/{chunk-6UAWTJ5S.js → chunk-Z532A7QC.js} +13 -20
- package/dist/{chunk-6UAWTJ5S.js.map → chunk-Z532A7QC.js.map} +1 -1
- package/dist/file-stream.d.ts +16 -38
- package/dist/file-stream.js +1 -2
- package/dist/index.d.ts +6 -5
- package/dist/index.js +35 -39
- package/dist/index.js.map +1 -1
- package/dist/interpreter.d.ts +3 -3
- package/dist/interpreter.js +2 -2
- package/dist/request-handler.d.ts +4 -3
- package/dist/request-handler.js +4 -7
- package/dist/sandbox-D9K2ypln.d.ts +583 -0
- package/dist/sandbox.d.ts +3 -3
- package/dist/sandbox.js +4 -7
- package/dist/security.d.ts +4 -3
- package/dist/security.js +3 -3
- package/dist/sse-parser.js +1 -1
- package/package.json +11 -5
- package/src/clients/base-client.ts +280 -0
- package/src/clients/command-client.ts +115 -0
- package/src/clients/file-client.ts +269 -0
- package/src/clients/git-client.ts +92 -0
- package/src/clients/index.ts +63 -0
- package/src/{interpreter-client.ts → clients/interpreter-client.ts} +148 -171
- package/src/clients/port-client.ts +105 -0
- package/src/clients/process-client.ts +177 -0
- package/src/clients/sandbox-client.ts +41 -0
- package/src/clients/types.ts +84 -0
- package/src/clients/utility-client.ts +94 -0
- package/src/errors/adapter.ts +180 -0
- package/src/errors/classes.ts +469 -0
- package/src/errors/index.ts +105 -0
- package/src/file-stream.ts +119 -117
- package/src/index.ts +81 -69
- package/src/interpreter.ts +17 -8
- package/src/request-handler.ts +69 -43
- package/src/sandbox.ts +694 -533
- package/src/security.ts +14 -23
- package/src/sse-parser.ts +4 -8
- package/startup.sh +3 -0
- package/tests/base-client.test.ts +328 -0
- package/tests/command-client.test.ts +407 -0
- package/tests/file-client.test.ts +643 -0
- package/tests/file-stream.test.ts +306 -0
- package/tests/git-client.test.ts +328 -0
- package/tests/port-client.test.ts +301 -0
- package/tests/process-client.test.ts +658 -0
- package/tests/sandbox.test.ts +465 -0
- package/tests/sse-parser.test.ts +290 -0
- package/tests/utility-client.test.ts +266 -0
- package/tests/wrangler.jsonc +35 -0
- package/tsconfig.json +9 -1
- package/vitest.config.ts +31 -0
- package/container_src/bun.lock +0 -76
- package/container_src/circuit-breaker.ts +0 -121
- package/container_src/control-process.ts +0 -784
- package/container_src/handler/exec.ts +0 -185
- package/container_src/handler/file.ts +0 -457
- package/container_src/handler/git.ts +0 -130
- package/container_src/handler/ports.ts +0 -314
- package/container_src/handler/process.ts +0 -568
- package/container_src/handler/session.ts +0 -92
- package/container_src/index.ts +0 -601
- package/container_src/interpreter-service.ts +0 -276
- package/container_src/isolation.ts +0 -1213
- package/container_src/mime-processor.ts +0 -255
- package/container_src/package.json +0 -18
- package/container_src/runtime/executors/javascript/node_executor.ts +0 -123
- package/container_src/runtime/executors/python/ipython_executor.py +0 -338
- package/container_src/runtime/executors/typescript/ts_executor.ts +0 -138
- package/container_src/runtime/process-pool.ts +0 -464
- package/container_src/shell-escape.ts +0 -42
- package/container_src/startup.sh +0 -11
- package/container_src/types.ts +0 -131
- package/dist/chunk-32UDXUPC.js +0 -671
- package/dist/chunk-32UDXUPC.js.map +0 -1
- package/dist/chunk-5DILEXGY.js +0 -85
- package/dist/chunk-5DILEXGY.js.map +0 -1
- package/dist/chunk-D3U63BZP.js +0 -240
- package/dist/chunk-D3U63BZP.js.map +0 -1
- package/dist/chunk-FXYPFGOZ.js +0 -129
- package/dist/chunk-FXYPFGOZ.js.map +0 -1
- package/dist/chunk-JTKON2SH.js.map +0 -1
- package/dist/chunk-NNGBXDMY.js.map +0 -1
- package/dist/chunk-SQLJNZ3K.js +0 -674
- package/dist/chunk-SQLJNZ3K.js.map +0 -1
- package/dist/chunk-W7TVRPBG.js +0 -108
- package/dist/chunk-W7TVRPBG.js.map +0 -1
- package/dist/client-B3RUab0s.d.ts +0 -225
- package/dist/client.d.ts +0 -4
- package/dist/client.js +0 -7
- package/dist/client.js.map +0 -1
- package/dist/errors.d.ts +0 -95
- package/dist/errors.js +0 -27
- package/dist/errors.js.map +0 -1
- package/dist/interpreter-client.d.ts +0 -4
- package/dist/interpreter-client.js +0 -9
- package/dist/interpreter-client.js.map +0 -1
- package/dist/interpreter-types.d.ts +0 -259
- package/dist/interpreter-types.js +0 -9
- package/dist/interpreter-types.js.map +0 -1
- package/dist/types.d.ts +0 -453
- package/dist/types.js +0 -45
- package/dist/types.js.map +0 -1
- package/src/client.ts +0 -1048
- package/src/errors.ts +0 -219
- package/src/interpreter-types.ts +0 -390
- package/src/types.ts +0 -571
|
@@ -1,259 +0,0 @@
|
|
|
1
|
-
interface CreateContextOptions {
|
|
2
|
-
/**
|
|
3
|
-
* Programming language for the context
|
|
4
|
-
* @default 'python'
|
|
5
|
-
*/
|
|
6
|
-
language?: "python" | "javascript" | "typescript";
|
|
7
|
-
/**
|
|
8
|
-
* Working directory for the context
|
|
9
|
-
* @default '/workspace'
|
|
10
|
-
*/
|
|
11
|
-
cwd?: string;
|
|
12
|
-
/**
|
|
13
|
-
* Environment variables for the context
|
|
14
|
-
*/
|
|
15
|
-
envVars?: Record<string, string>;
|
|
16
|
-
/**
|
|
17
|
-
* Request timeout in milliseconds
|
|
18
|
-
* @default 30000
|
|
19
|
-
*/
|
|
20
|
-
timeout?: number;
|
|
21
|
-
}
|
|
22
|
-
interface CodeContext {
|
|
23
|
-
/**
|
|
24
|
-
* Unique identifier for the context
|
|
25
|
-
*/
|
|
26
|
-
readonly id: string;
|
|
27
|
-
/**
|
|
28
|
-
* Programming language of the context
|
|
29
|
-
*/
|
|
30
|
-
readonly language: string;
|
|
31
|
-
/**
|
|
32
|
-
* Current working directory
|
|
33
|
-
*/
|
|
34
|
-
readonly cwd: string;
|
|
35
|
-
/**
|
|
36
|
-
* When the context was created
|
|
37
|
-
*/
|
|
38
|
-
readonly createdAt: Date;
|
|
39
|
-
/**
|
|
40
|
-
* When the context was last used
|
|
41
|
-
*/
|
|
42
|
-
readonly lastUsed: Date;
|
|
43
|
-
}
|
|
44
|
-
interface RunCodeOptions {
|
|
45
|
-
/**
|
|
46
|
-
* Context to run the code in. If not provided, uses default context for the language
|
|
47
|
-
*/
|
|
48
|
-
context?: CodeContext;
|
|
49
|
-
/**
|
|
50
|
-
* Language to use if context is not provided
|
|
51
|
-
* @default 'python'
|
|
52
|
-
*/
|
|
53
|
-
language?: "python" | "javascript" | "typescript";
|
|
54
|
-
/**
|
|
55
|
-
* Environment variables for this execution
|
|
56
|
-
*/
|
|
57
|
-
envVars?: Record<string, string>;
|
|
58
|
-
/**
|
|
59
|
-
* Execution timeout in milliseconds
|
|
60
|
-
* @default 60000
|
|
61
|
-
*/
|
|
62
|
-
timeout?: number;
|
|
63
|
-
/**
|
|
64
|
-
* AbortSignal for cancelling execution
|
|
65
|
-
*/
|
|
66
|
-
signal?: AbortSignal;
|
|
67
|
-
/**
|
|
68
|
-
* Callback for stdout output
|
|
69
|
-
*/
|
|
70
|
-
onStdout?: (output: OutputMessage) => void | Promise<void>;
|
|
71
|
-
/**
|
|
72
|
-
* Callback for stderr output
|
|
73
|
-
*/
|
|
74
|
-
onStderr?: (output: OutputMessage) => void | Promise<void>;
|
|
75
|
-
/**
|
|
76
|
-
* Callback for execution results (charts, tables, etc)
|
|
77
|
-
*/
|
|
78
|
-
onResult?: (result: Result) => void | Promise<void>;
|
|
79
|
-
/**
|
|
80
|
-
* Callback for execution errors
|
|
81
|
-
*/
|
|
82
|
-
onError?: (error: ExecutionError) => void | Promise<void>;
|
|
83
|
-
}
|
|
84
|
-
interface OutputMessage {
|
|
85
|
-
/**
|
|
86
|
-
* The output text
|
|
87
|
-
*/
|
|
88
|
-
text: string;
|
|
89
|
-
/**
|
|
90
|
-
* Timestamp of the output
|
|
91
|
-
*/
|
|
92
|
-
timestamp: number;
|
|
93
|
-
}
|
|
94
|
-
interface Result {
|
|
95
|
-
/**
|
|
96
|
-
* Plain text representation
|
|
97
|
-
*/
|
|
98
|
-
text?: string;
|
|
99
|
-
/**
|
|
100
|
-
* HTML representation (tables, formatted output)
|
|
101
|
-
*/
|
|
102
|
-
html?: string;
|
|
103
|
-
/**
|
|
104
|
-
* PNG image data (base64 encoded)
|
|
105
|
-
*/
|
|
106
|
-
png?: string;
|
|
107
|
-
/**
|
|
108
|
-
* JPEG image data (base64 encoded)
|
|
109
|
-
*/
|
|
110
|
-
jpeg?: string;
|
|
111
|
-
/**
|
|
112
|
-
* SVG image data
|
|
113
|
-
*/
|
|
114
|
-
svg?: string;
|
|
115
|
-
/**
|
|
116
|
-
* LaTeX representation
|
|
117
|
-
*/
|
|
118
|
-
latex?: string;
|
|
119
|
-
/**
|
|
120
|
-
* Markdown representation
|
|
121
|
-
*/
|
|
122
|
-
markdown?: string;
|
|
123
|
-
/**
|
|
124
|
-
* JavaScript code to execute
|
|
125
|
-
*/
|
|
126
|
-
javascript?: string;
|
|
127
|
-
/**
|
|
128
|
-
* JSON data
|
|
129
|
-
*/
|
|
130
|
-
json?: any;
|
|
131
|
-
/**
|
|
132
|
-
* Chart data if the result is a visualization
|
|
133
|
-
*/
|
|
134
|
-
chart?: ChartData;
|
|
135
|
-
/**
|
|
136
|
-
* Raw data object
|
|
137
|
-
*/
|
|
138
|
-
data?: any;
|
|
139
|
-
/**
|
|
140
|
-
* Available output formats
|
|
141
|
-
*/
|
|
142
|
-
formats(): string[];
|
|
143
|
-
}
|
|
144
|
-
interface ChartData {
|
|
145
|
-
/**
|
|
146
|
-
* Type of chart
|
|
147
|
-
*/
|
|
148
|
-
type: "line" | "bar" | "scatter" | "pie" | "histogram" | "heatmap" | "unknown";
|
|
149
|
-
/**
|
|
150
|
-
* Chart title
|
|
151
|
-
*/
|
|
152
|
-
title?: string;
|
|
153
|
-
/**
|
|
154
|
-
* Chart data (format depends on library)
|
|
155
|
-
*/
|
|
156
|
-
data: any;
|
|
157
|
-
/**
|
|
158
|
-
* Chart layout/configuration
|
|
159
|
-
*/
|
|
160
|
-
layout?: any;
|
|
161
|
-
/**
|
|
162
|
-
* Additional configuration
|
|
163
|
-
*/
|
|
164
|
-
config?: any;
|
|
165
|
-
/**
|
|
166
|
-
* Library that generated the chart
|
|
167
|
-
*/
|
|
168
|
-
library?: "matplotlib" | "plotly" | "altair" | "seaborn" | "unknown";
|
|
169
|
-
/**
|
|
170
|
-
* Base64 encoded image if available
|
|
171
|
-
*/
|
|
172
|
-
image?: string;
|
|
173
|
-
}
|
|
174
|
-
interface ExecutionError {
|
|
175
|
-
/**
|
|
176
|
-
* Error name/type (e.g., 'NameError', 'SyntaxError')
|
|
177
|
-
*/
|
|
178
|
-
name: string;
|
|
179
|
-
/**
|
|
180
|
-
* Error message
|
|
181
|
-
*/
|
|
182
|
-
value: string;
|
|
183
|
-
/**
|
|
184
|
-
* Stack trace
|
|
185
|
-
*/
|
|
186
|
-
traceback: string[];
|
|
187
|
-
/**
|
|
188
|
-
* Line number where error occurred
|
|
189
|
-
*/
|
|
190
|
-
lineNumber?: number;
|
|
191
|
-
}
|
|
192
|
-
interface ExecutionResult {
|
|
193
|
-
code: string;
|
|
194
|
-
logs: {
|
|
195
|
-
stdout: string[];
|
|
196
|
-
stderr: string[];
|
|
197
|
-
};
|
|
198
|
-
error?: ExecutionError;
|
|
199
|
-
executionCount?: number;
|
|
200
|
-
results: Array<{
|
|
201
|
-
text?: string;
|
|
202
|
-
html?: string;
|
|
203
|
-
png?: string;
|
|
204
|
-
jpeg?: string;
|
|
205
|
-
svg?: string;
|
|
206
|
-
latex?: string;
|
|
207
|
-
markdown?: string;
|
|
208
|
-
javascript?: string;
|
|
209
|
-
json?: any;
|
|
210
|
-
chart?: ChartData;
|
|
211
|
-
data?: any;
|
|
212
|
-
}>;
|
|
213
|
-
}
|
|
214
|
-
declare class Execution {
|
|
215
|
-
readonly code: string;
|
|
216
|
-
readonly context: CodeContext;
|
|
217
|
-
/**
|
|
218
|
-
* All results from the execution
|
|
219
|
-
*/
|
|
220
|
-
results: Result[];
|
|
221
|
-
/**
|
|
222
|
-
* Accumulated stdout and stderr
|
|
223
|
-
*/
|
|
224
|
-
logs: {
|
|
225
|
-
stdout: string[];
|
|
226
|
-
stderr: string[];
|
|
227
|
-
};
|
|
228
|
-
/**
|
|
229
|
-
* Execution error if any
|
|
230
|
-
*/
|
|
231
|
-
error?: ExecutionError;
|
|
232
|
-
/**
|
|
233
|
-
* Execution count (for interpreter)
|
|
234
|
-
*/
|
|
235
|
-
executionCount?: number;
|
|
236
|
-
constructor(code: string, context: CodeContext);
|
|
237
|
-
/**
|
|
238
|
-
* Convert to a plain object for serialization
|
|
239
|
-
*/
|
|
240
|
-
toJSON(): ExecutionResult;
|
|
241
|
-
}
|
|
242
|
-
declare class ResultImpl implements Result {
|
|
243
|
-
private raw;
|
|
244
|
-
constructor(raw: any);
|
|
245
|
-
get text(): string | undefined;
|
|
246
|
-
get html(): string | undefined;
|
|
247
|
-
get png(): string | undefined;
|
|
248
|
-
get jpeg(): string | undefined;
|
|
249
|
-
get svg(): string | undefined;
|
|
250
|
-
get latex(): string | undefined;
|
|
251
|
-
get markdown(): string | undefined;
|
|
252
|
-
get javascript(): string | undefined;
|
|
253
|
-
get json(): any;
|
|
254
|
-
get chart(): ChartData | undefined;
|
|
255
|
-
get data(): any;
|
|
256
|
-
formats(): string[];
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
export { type ChartData, type CodeContext, type CreateContextOptions, Execution, type ExecutionError, type ExecutionResult, type OutputMessage, type Result, ResultImpl, type RunCodeOptions };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/types.d.ts
DELETED
|
@@ -1,453 +0,0 @@
|
|
|
1
|
-
import { CreateContextOptions, CodeContext, RunCodeOptions, ExecutionResult } from './interpreter-types.js';
|
|
2
|
-
|
|
3
|
-
interface BaseExecOptions {
|
|
4
|
-
/**
|
|
5
|
-
* Maximum execution time in milliseconds
|
|
6
|
-
*/
|
|
7
|
-
timeout?: number;
|
|
8
|
-
/**
|
|
9
|
-
* Environment variables for the command
|
|
10
|
-
*/
|
|
11
|
-
env?: Record<string, string>;
|
|
12
|
-
/**
|
|
13
|
-
* Working directory for command execution
|
|
14
|
-
*/
|
|
15
|
-
cwd?: string;
|
|
16
|
-
/**
|
|
17
|
-
* Text encoding for output (default: 'utf8')
|
|
18
|
-
*/
|
|
19
|
-
encoding?: string;
|
|
20
|
-
}
|
|
21
|
-
interface ExecOptions extends BaseExecOptions {
|
|
22
|
-
/**
|
|
23
|
-
* Enable real-time output streaming via callbacks
|
|
24
|
-
*/
|
|
25
|
-
stream?: boolean;
|
|
26
|
-
/**
|
|
27
|
-
* Callback for real-time output data
|
|
28
|
-
*/
|
|
29
|
-
onOutput?: (stream: 'stdout' | 'stderr', data: string) => void;
|
|
30
|
-
/**
|
|
31
|
-
* Callback when command completes (only when stream: true)
|
|
32
|
-
*/
|
|
33
|
-
onComplete?: (result: ExecResult) => void;
|
|
34
|
-
/**
|
|
35
|
-
* Callback for execution errors
|
|
36
|
-
*/
|
|
37
|
-
onError?: (error: Error) => void;
|
|
38
|
-
/**
|
|
39
|
-
* AbortSignal for cancelling execution
|
|
40
|
-
*/
|
|
41
|
-
signal?: AbortSignal;
|
|
42
|
-
}
|
|
43
|
-
interface ExecResult {
|
|
44
|
-
/**
|
|
45
|
-
* Whether the command succeeded (exitCode === 0)
|
|
46
|
-
*/
|
|
47
|
-
success: boolean;
|
|
48
|
-
/**
|
|
49
|
-
* Process exit code
|
|
50
|
-
*/
|
|
51
|
-
exitCode: number;
|
|
52
|
-
/**
|
|
53
|
-
* Standard output content
|
|
54
|
-
*/
|
|
55
|
-
stdout: string;
|
|
56
|
-
/**
|
|
57
|
-
* Standard error content
|
|
58
|
-
*/
|
|
59
|
-
stderr: string;
|
|
60
|
-
/**
|
|
61
|
-
* Command that was executed
|
|
62
|
-
*/
|
|
63
|
-
command: string;
|
|
64
|
-
/**
|
|
65
|
-
* Execution duration in milliseconds
|
|
66
|
-
*/
|
|
67
|
-
duration: number;
|
|
68
|
-
/**
|
|
69
|
-
* ISO timestamp when command started
|
|
70
|
-
*/
|
|
71
|
-
timestamp: string;
|
|
72
|
-
}
|
|
73
|
-
interface ProcessOptions extends BaseExecOptions {
|
|
74
|
-
/**
|
|
75
|
-
* Custom process ID for later reference
|
|
76
|
-
* If not provided, a UUID will be generated
|
|
77
|
-
*/
|
|
78
|
-
processId?: string;
|
|
79
|
-
/**
|
|
80
|
-
* Automatically cleanup process record after exit (default: true)
|
|
81
|
-
*/
|
|
82
|
-
autoCleanup?: boolean;
|
|
83
|
-
/**
|
|
84
|
-
* Callback when process exits
|
|
85
|
-
*/
|
|
86
|
-
onExit?: (code: number | null) => void;
|
|
87
|
-
/**
|
|
88
|
-
* Callback for real-time output (background processes)
|
|
89
|
-
*/
|
|
90
|
-
onOutput?: (stream: 'stdout' | 'stderr', data: string) => void;
|
|
91
|
-
/**
|
|
92
|
-
* Callback when process starts successfully
|
|
93
|
-
*/
|
|
94
|
-
onStart?: (process: Process) => void;
|
|
95
|
-
/**
|
|
96
|
-
* Callback for process errors
|
|
97
|
-
*/
|
|
98
|
-
onError?: (error: Error) => void;
|
|
99
|
-
}
|
|
100
|
-
type ProcessStatus = 'starting' | 'running' | 'completed' | 'failed' | 'killed' | 'error';
|
|
101
|
-
interface Process {
|
|
102
|
-
/**
|
|
103
|
-
* Unique process identifier
|
|
104
|
-
*/
|
|
105
|
-
readonly id: string;
|
|
106
|
-
/**
|
|
107
|
-
* System process ID (if available and running)
|
|
108
|
-
*/
|
|
109
|
-
readonly pid?: number;
|
|
110
|
-
/**
|
|
111
|
-
* Command that was executed
|
|
112
|
-
*/
|
|
113
|
-
readonly command: string;
|
|
114
|
-
/**
|
|
115
|
-
* Current process status
|
|
116
|
-
*/
|
|
117
|
-
readonly status: ProcessStatus;
|
|
118
|
-
/**
|
|
119
|
-
* When the process was started
|
|
120
|
-
*/
|
|
121
|
-
readonly startTime: Date;
|
|
122
|
-
/**
|
|
123
|
-
* When the process ended (if completed)
|
|
124
|
-
*/
|
|
125
|
-
readonly endTime?: Date;
|
|
126
|
-
/**
|
|
127
|
-
* Process exit code (if completed)
|
|
128
|
-
*/
|
|
129
|
-
readonly exitCode?: number;
|
|
130
|
-
/**
|
|
131
|
-
* Kill the process
|
|
132
|
-
*/
|
|
133
|
-
kill(signal?: string): Promise<void>;
|
|
134
|
-
/**
|
|
135
|
-
* Get current process status (refreshed)
|
|
136
|
-
*/
|
|
137
|
-
getStatus(): Promise<ProcessStatus>;
|
|
138
|
-
/**
|
|
139
|
-
* Get accumulated logs
|
|
140
|
-
*/
|
|
141
|
-
getLogs(): Promise<{
|
|
142
|
-
stdout: string;
|
|
143
|
-
stderr: string;
|
|
144
|
-
}>;
|
|
145
|
-
}
|
|
146
|
-
interface ExecEvent {
|
|
147
|
-
type: 'start' | 'stdout' | 'stderr' | 'complete' | 'error';
|
|
148
|
-
timestamp: string;
|
|
149
|
-
data?: string;
|
|
150
|
-
command?: string;
|
|
151
|
-
exitCode?: number;
|
|
152
|
-
result?: ExecResult;
|
|
153
|
-
error?: string;
|
|
154
|
-
}
|
|
155
|
-
interface LogEvent {
|
|
156
|
-
type: 'stdout' | 'stderr' | 'exit' | 'error';
|
|
157
|
-
timestamp: string;
|
|
158
|
-
data: string;
|
|
159
|
-
processId: string;
|
|
160
|
-
exitCode?: number;
|
|
161
|
-
}
|
|
162
|
-
interface StreamOptions extends BaseExecOptions {
|
|
163
|
-
/**
|
|
164
|
-
* Buffer size for streaming output
|
|
165
|
-
*/
|
|
166
|
-
bufferSize?: number;
|
|
167
|
-
/**
|
|
168
|
-
* AbortSignal for cancelling stream
|
|
169
|
-
*/
|
|
170
|
-
signal?: AbortSignal;
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* SSE events for file streaming
|
|
174
|
-
*/
|
|
175
|
-
type FileStreamEvent = {
|
|
176
|
-
type: 'metadata';
|
|
177
|
-
mimeType: string;
|
|
178
|
-
size: number;
|
|
179
|
-
isBinary: boolean;
|
|
180
|
-
encoding: 'utf-8' | 'base64';
|
|
181
|
-
} | {
|
|
182
|
-
type: 'chunk';
|
|
183
|
-
data: string;
|
|
184
|
-
} | {
|
|
185
|
-
type: 'complete';
|
|
186
|
-
bytesRead: number;
|
|
187
|
-
} | {
|
|
188
|
-
type: 'error';
|
|
189
|
-
error: string;
|
|
190
|
-
};
|
|
191
|
-
/**
|
|
192
|
-
* File metadata from streaming
|
|
193
|
-
*/
|
|
194
|
-
interface FileMetadata {
|
|
195
|
-
mimeType: string;
|
|
196
|
-
size: number;
|
|
197
|
-
isBinary: boolean;
|
|
198
|
-
encoding: 'utf-8' | 'base64';
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* File stream chunk - either string (text) or Uint8Array (binary, auto-decoded)
|
|
202
|
-
*/
|
|
203
|
-
type FileChunk = string | Uint8Array;
|
|
204
|
-
/**
|
|
205
|
-
* AsyncIterable of file chunks with metadata
|
|
206
|
-
*/
|
|
207
|
-
interface FileStream extends AsyncIterable<FileChunk> {
|
|
208
|
-
metadata?: FileMetadata;
|
|
209
|
-
}
|
|
210
|
-
declare class SandboxError extends Error {
|
|
211
|
-
code?: string | undefined;
|
|
212
|
-
constructor(message: string, code?: string | undefined);
|
|
213
|
-
}
|
|
214
|
-
declare class ProcessNotFoundError extends SandboxError {
|
|
215
|
-
constructor(processId: string);
|
|
216
|
-
}
|
|
217
|
-
declare class ProcessAlreadyExistsError extends SandboxError {
|
|
218
|
-
constructor(processId: string);
|
|
219
|
-
}
|
|
220
|
-
declare class ExecutionTimeoutError extends SandboxError {
|
|
221
|
-
constructor(timeout: number);
|
|
222
|
-
}
|
|
223
|
-
interface ProcessRecord {
|
|
224
|
-
id: string;
|
|
225
|
-
pid?: number;
|
|
226
|
-
command: string;
|
|
227
|
-
status: ProcessStatus;
|
|
228
|
-
startTime: Date;
|
|
229
|
-
endTime?: Date;
|
|
230
|
-
exitCode?: number;
|
|
231
|
-
stdout: string;
|
|
232
|
-
stderr: string;
|
|
233
|
-
outputListeners: Set<(stream: 'stdout' | 'stderr', data: string) => void>;
|
|
234
|
-
statusListeners: Set<(status: ProcessStatus) => void>;
|
|
235
|
-
}
|
|
236
|
-
interface StartProcessRequest {
|
|
237
|
-
command: string;
|
|
238
|
-
options?: {
|
|
239
|
-
processId?: string;
|
|
240
|
-
timeout?: number;
|
|
241
|
-
env?: Record<string, string>;
|
|
242
|
-
cwd?: string;
|
|
243
|
-
encoding?: string;
|
|
244
|
-
autoCleanup?: boolean;
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
interface StartProcessResponse {
|
|
248
|
-
process: {
|
|
249
|
-
id: string;
|
|
250
|
-
pid?: number;
|
|
251
|
-
command: string;
|
|
252
|
-
status: ProcessStatus;
|
|
253
|
-
startTime: string;
|
|
254
|
-
endTime?: string | null;
|
|
255
|
-
exitCode?: number | null;
|
|
256
|
-
sessionId: string;
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
interface ListProcessesResponse {
|
|
260
|
-
processes: Array<{
|
|
261
|
-
id: string;
|
|
262
|
-
pid?: number;
|
|
263
|
-
command: string;
|
|
264
|
-
status: ProcessStatus;
|
|
265
|
-
startTime: string;
|
|
266
|
-
endTime?: string;
|
|
267
|
-
exitCode?: number;
|
|
268
|
-
}>;
|
|
269
|
-
}
|
|
270
|
-
interface GetProcessResponse {
|
|
271
|
-
process: {
|
|
272
|
-
id: string;
|
|
273
|
-
pid?: number;
|
|
274
|
-
command: string;
|
|
275
|
-
status: ProcessStatus;
|
|
276
|
-
startTime: string;
|
|
277
|
-
endTime?: string;
|
|
278
|
-
exitCode?: number;
|
|
279
|
-
} | null;
|
|
280
|
-
}
|
|
281
|
-
interface GetProcessLogsResponse {
|
|
282
|
-
stdout: string;
|
|
283
|
-
stderr: string;
|
|
284
|
-
processId: string;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
interface ISandbox {
|
|
288
|
-
exec(command: string, options?: ExecOptions): Promise<ExecResult>;
|
|
289
|
-
startProcess(command: string, options?: ProcessOptions): Promise<Process>;
|
|
290
|
-
listProcesses(): Promise<Process[]>;
|
|
291
|
-
getProcess(id: string): Promise<Process | null>;
|
|
292
|
-
killProcess(id: string, signal?: string): Promise<void>;
|
|
293
|
-
killAllProcesses(): Promise<number>;
|
|
294
|
-
execStream(command: string, options?: StreamOptions): Promise<ReadableStream<Uint8Array>>;
|
|
295
|
-
streamProcessLogs(processId: string, options?: {
|
|
296
|
-
signal?: AbortSignal;
|
|
297
|
-
}): Promise<ReadableStream<Uint8Array>>;
|
|
298
|
-
cleanupCompletedProcesses(): Promise<number>;
|
|
299
|
-
getProcessLogs(id: string): Promise<{
|
|
300
|
-
stdout: string;
|
|
301
|
-
stderr: string;
|
|
302
|
-
}>;
|
|
303
|
-
gitCheckout(repoUrl: string, options: {
|
|
304
|
-
branch?: string;
|
|
305
|
-
targetDir?: string;
|
|
306
|
-
}): Promise<GitCheckoutResponse>;
|
|
307
|
-
mkdir(path: string, options?: {
|
|
308
|
-
recursive?: boolean;
|
|
309
|
-
}): Promise<MkdirResponse>;
|
|
310
|
-
writeFile(path: string, content: string, options?: {
|
|
311
|
-
encoding?: string;
|
|
312
|
-
}): Promise<WriteFileResponse>;
|
|
313
|
-
deleteFile(path: string): Promise<DeleteFileResponse>;
|
|
314
|
-
renameFile(oldPath: string, newPath: string): Promise<RenameFileResponse>;
|
|
315
|
-
moveFile(sourcePath: string, destinationPath: string): Promise<MoveFileResponse>;
|
|
316
|
-
readFile(path: string, options?: {
|
|
317
|
-
encoding?: string;
|
|
318
|
-
}): Promise<ReadFileResponse>;
|
|
319
|
-
readFileStream(path: string): Promise<ReadableStream<Uint8Array>>;
|
|
320
|
-
listFiles(path: string, options?: {
|
|
321
|
-
recursive?: boolean;
|
|
322
|
-
includeHidden?: boolean;
|
|
323
|
-
}): Promise<ListFilesResponse>;
|
|
324
|
-
exposePort(port: number, options: {
|
|
325
|
-
name?: string;
|
|
326
|
-
hostname: string;
|
|
327
|
-
}): Promise<{
|
|
328
|
-
url: string;
|
|
329
|
-
port: number;
|
|
330
|
-
name?: string;
|
|
331
|
-
}>;
|
|
332
|
-
unexposePort(port: number): Promise<void>;
|
|
333
|
-
getExposedPorts(hostname: string): Promise<Array<{
|
|
334
|
-
url: string;
|
|
335
|
-
port: number;
|
|
336
|
-
name?: string;
|
|
337
|
-
exposedAt: string;
|
|
338
|
-
}>>;
|
|
339
|
-
setEnvVars(envVars: Record<string, string>): Promise<void>;
|
|
340
|
-
setSandboxName(name: string): Promise<void>;
|
|
341
|
-
createCodeContext(options?: CreateContextOptions): Promise<CodeContext>;
|
|
342
|
-
runCode(code: string, options?: RunCodeOptions): Promise<ExecutionResult>;
|
|
343
|
-
runCodeStream(code: string, options?: RunCodeOptions): Promise<ReadableStream>;
|
|
344
|
-
listCodeContexts(): Promise<CodeContext[]>;
|
|
345
|
-
deleteCodeContext(contextId: string): Promise<void>;
|
|
346
|
-
}
|
|
347
|
-
interface ExecutionSession extends Omit<ISandbox, 'createSession' | 'setSandboxName'> {
|
|
348
|
-
/**
|
|
349
|
-
* Session ID
|
|
350
|
-
*/
|
|
351
|
-
id: string;
|
|
352
|
-
}
|
|
353
|
-
interface ExecuteResponse {
|
|
354
|
-
success: boolean;
|
|
355
|
-
stdout: string;
|
|
356
|
-
stderr: string;
|
|
357
|
-
exitCode: number;
|
|
358
|
-
command: string;
|
|
359
|
-
timestamp: string;
|
|
360
|
-
}
|
|
361
|
-
interface GitCheckoutResponse {
|
|
362
|
-
success: boolean;
|
|
363
|
-
stdout: string;
|
|
364
|
-
stderr: string;
|
|
365
|
-
exitCode: number;
|
|
366
|
-
repoUrl: string;
|
|
367
|
-
branch: string;
|
|
368
|
-
targetDir: string;
|
|
369
|
-
timestamp: string;
|
|
370
|
-
}
|
|
371
|
-
interface MkdirResponse {
|
|
372
|
-
success: boolean;
|
|
373
|
-
stdout: string;
|
|
374
|
-
stderr: string;
|
|
375
|
-
exitCode: number;
|
|
376
|
-
path: string;
|
|
377
|
-
recursive: boolean;
|
|
378
|
-
timestamp: string;
|
|
379
|
-
}
|
|
380
|
-
interface WriteFileResponse {
|
|
381
|
-
success: boolean;
|
|
382
|
-
exitCode: number;
|
|
383
|
-
path: string;
|
|
384
|
-
timestamp: string;
|
|
385
|
-
}
|
|
386
|
-
interface ReadFileResponse {
|
|
387
|
-
success: boolean;
|
|
388
|
-
exitCode: number;
|
|
389
|
-
path: string;
|
|
390
|
-
content: string;
|
|
391
|
-
timestamp: string;
|
|
392
|
-
/**
|
|
393
|
-
* Encoding used for content (utf-8 for text, base64 for binary)
|
|
394
|
-
*/
|
|
395
|
-
encoding?: 'utf-8' | 'base64';
|
|
396
|
-
/**
|
|
397
|
-
* Whether the file is detected as binary
|
|
398
|
-
*/
|
|
399
|
-
isBinary?: boolean;
|
|
400
|
-
/**
|
|
401
|
-
* MIME type of the file (e.g., 'image/png', 'text/plain')
|
|
402
|
-
*/
|
|
403
|
-
mimeType?: string;
|
|
404
|
-
/**
|
|
405
|
-
* File size in bytes
|
|
406
|
-
*/
|
|
407
|
-
size?: number;
|
|
408
|
-
}
|
|
409
|
-
interface DeleteFileResponse {
|
|
410
|
-
success: boolean;
|
|
411
|
-
exitCode: number;
|
|
412
|
-
path: string;
|
|
413
|
-
timestamp: string;
|
|
414
|
-
}
|
|
415
|
-
interface RenameFileResponse {
|
|
416
|
-
success: boolean;
|
|
417
|
-
exitCode: number;
|
|
418
|
-
oldPath: string;
|
|
419
|
-
newPath: string;
|
|
420
|
-
timestamp: string;
|
|
421
|
-
}
|
|
422
|
-
interface MoveFileResponse {
|
|
423
|
-
success: boolean;
|
|
424
|
-
exitCode: number;
|
|
425
|
-
sourcePath: string;
|
|
426
|
-
destinationPath: string;
|
|
427
|
-
timestamp: string;
|
|
428
|
-
}
|
|
429
|
-
interface ListFilesResponse {
|
|
430
|
-
success: boolean;
|
|
431
|
-
exitCode: number;
|
|
432
|
-
path: string;
|
|
433
|
-
files: Array<{
|
|
434
|
-
name: string;
|
|
435
|
-
absolutePath: string;
|
|
436
|
-
relativePath: string;
|
|
437
|
-
type: 'file' | 'directory' | 'symlink' | 'other';
|
|
438
|
-
size: number;
|
|
439
|
-
modifiedAt: string;
|
|
440
|
-
mode: string;
|
|
441
|
-
permissions: {
|
|
442
|
-
readable: boolean;
|
|
443
|
-
writable: boolean;
|
|
444
|
-
executable: boolean;
|
|
445
|
-
};
|
|
446
|
-
}>;
|
|
447
|
-
timestamp: string;
|
|
448
|
-
}
|
|
449
|
-
declare function isExecResult(value: any): value is ExecResult;
|
|
450
|
-
declare function isProcess(value: any): value is Process;
|
|
451
|
-
declare function isProcessStatus(value: string): value is ProcessStatus;
|
|
452
|
-
|
|
453
|
-
export { type BaseExecOptions, type DeleteFileResponse, type ExecEvent, type ExecOptions, type ExecResult, type ExecuteResponse, type ExecutionSession, ExecutionTimeoutError, type FileChunk, type FileMetadata, type FileStream, type FileStreamEvent, type GetProcessLogsResponse, type GetProcessResponse, type GitCheckoutResponse, type ISandbox, type ListFilesResponse, type ListProcessesResponse, type LogEvent, type MkdirResponse, type MoveFileResponse, type Process, ProcessAlreadyExistsError, ProcessNotFoundError, type ProcessOptions, type ProcessRecord, type ProcessStatus, type ReadFileResponse, type RenameFileResponse, SandboxError, type StartProcessRequest, type StartProcessResponse, type StreamOptions, type WriteFileResponse, isExecResult, isProcess, isProcessStatus };
|