@cloudflare/sandbox 0.0.0-af082ab → 0.0.0-b4913fb

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 (75) hide show
  1. package/CHANGELOG.md +156 -21
  2. package/Dockerfile +157 -70
  3. package/LICENSE +176 -0
  4. package/README.md +92 -822
  5. package/dist/index.d.ts +1953 -0
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.js +3280 -0
  8. package/dist/index.js.map +1 -0
  9. package/package.json +16 -8
  10. package/src/clients/base-client.ts +295 -0
  11. package/src/clients/command-client.ts +115 -0
  12. package/src/clients/file-client.ts +300 -0
  13. package/src/clients/git-client.ts +98 -0
  14. package/src/clients/index.ts +64 -0
  15. package/src/clients/interpreter-client.ts +333 -0
  16. package/src/clients/port-client.ts +105 -0
  17. package/src/clients/process-client.ts +180 -0
  18. package/src/clients/sandbox-client.ts +39 -0
  19. package/src/clients/types.ts +88 -0
  20. package/src/clients/utility-client.ts +156 -0
  21. package/src/errors/adapter.ts +238 -0
  22. package/src/errors/classes.ts +594 -0
  23. package/src/errors/index.ts +109 -0
  24. package/src/file-stream.ts +123 -116
  25. package/src/index.ts +89 -66
  26. package/src/interpreter.ts +58 -40
  27. package/src/request-handler.ts +94 -55
  28. package/src/sandbox.ts +1009 -497
  29. package/src/security.ts +34 -28
  30. package/src/sse-parser.ts +8 -11
  31. package/src/version.ts +6 -0
  32. package/startup.sh +3 -0
  33. package/tests/base-client.test.ts +364 -0
  34. package/tests/command-client.test.ts +444 -0
  35. package/tests/file-client.test.ts +831 -0
  36. package/tests/file-stream.test.ts +310 -0
  37. package/tests/get-sandbox.test.ts +149 -0
  38. package/tests/git-client.test.ts +487 -0
  39. package/tests/port-client.test.ts +293 -0
  40. package/tests/process-client.test.ts +683 -0
  41. package/tests/request-handler.test.ts +292 -0
  42. package/tests/sandbox.test.ts +739 -0
  43. package/tests/sse-parser.test.ts +291 -0
  44. package/tests/utility-client.test.ts +339 -0
  45. package/tests/version.test.ts +16 -0
  46. package/tests/wrangler.jsonc +35 -0
  47. package/tsconfig.json +9 -1
  48. package/tsdown.config.ts +12 -0
  49. package/vitest.config.ts +31 -0
  50. package/container_src/bun.lock +0 -76
  51. package/container_src/circuit-breaker.ts +0 -121
  52. package/container_src/control-process.ts +0 -784
  53. package/container_src/handler/exec.ts +0 -185
  54. package/container_src/handler/file.ts +0 -457
  55. package/container_src/handler/git.ts +0 -130
  56. package/container_src/handler/ports.ts +0 -314
  57. package/container_src/handler/process.ts +0 -568
  58. package/container_src/handler/session.ts +0 -92
  59. package/container_src/index.ts +0 -601
  60. package/container_src/interpreter-service.ts +0 -276
  61. package/container_src/isolation.ts +0 -1213
  62. package/container_src/mime-processor.ts +0 -255
  63. package/container_src/package.json +0 -18
  64. package/container_src/runtime/executors/javascript/node_executor.ts +0 -123
  65. package/container_src/runtime/executors/python/ipython_executor.py +0 -338
  66. package/container_src/runtime/executors/typescript/ts_executor.ts +0 -138
  67. package/container_src/runtime/process-pool.ts +0 -464
  68. package/container_src/shell-escape.ts +0 -42
  69. package/container_src/startup.sh +0 -11
  70. package/container_src/types.ts +0 -131
  71. package/src/client.ts +0 -1048
  72. package/src/errors.ts +0 -219
  73. package/src/interpreter-client.ts +0 -352
  74. package/src/interpreter-types.ts +0 -390
  75. package/src/types.ts +0 -571
@@ -1,390 +0,0 @@
1
- // Context Management
2
- export interface CreateContextOptions {
3
- /**
4
- * Programming language for the context
5
- * @default 'python'
6
- */
7
- language?: "python" | "javascript" | "typescript";
8
-
9
- /**
10
- * Working directory for the context
11
- * @default '/workspace'
12
- */
13
- cwd?: string;
14
-
15
- /**
16
- * Environment variables for the context
17
- */
18
- envVars?: Record<string, string>;
19
-
20
- /**
21
- * Request timeout in milliseconds
22
- * @default 30000
23
- */
24
- timeout?: number;
25
- }
26
-
27
- export interface CodeContext {
28
- /**
29
- * Unique identifier for the context
30
- */
31
- readonly id: string;
32
-
33
- /**
34
- * Programming language of the context
35
- */
36
- readonly language: string;
37
-
38
- /**
39
- * Current working directory
40
- */
41
- readonly cwd: string;
42
-
43
- /**
44
- * When the context was created
45
- */
46
- readonly createdAt: Date;
47
-
48
- /**
49
- * When the context was last used
50
- */
51
- readonly lastUsed: Date;
52
- }
53
-
54
- // Execution Options
55
- export interface RunCodeOptions {
56
- /**
57
- * Context to run the code in. If not provided, uses default context for the language
58
- */
59
- context?: CodeContext;
60
-
61
- /**
62
- * Language to use if context is not provided
63
- * @default 'python'
64
- */
65
- language?: "python" | "javascript" | "typescript";
66
-
67
- /**
68
- * Environment variables for this execution
69
- */
70
- envVars?: Record<string, string>;
71
-
72
- /**
73
- * Execution timeout in milliseconds
74
- * @default 60000
75
- */
76
- timeout?: number;
77
-
78
- /**
79
- * AbortSignal for cancelling execution
80
- */
81
- signal?: AbortSignal;
82
-
83
- /**
84
- * Callback for stdout output
85
- */
86
- onStdout?: (output: OutputMessage) => void | Promise<void>;
87
-
88
- /**
89
- * Callback for stderr output
90
- */
91
- onStderr?: (output: OutputMessage) => void | Promise<void>;
92
-
93
- /**
94
- * Callback for execution results (charts, tables, etc)
95
- */
96
- onResult?: (result: Result) => void | Promise<void>;
97
-
98
- /**
99
- * Callback for execution errors
100
- */
101
- onError?: (error: ExecutionError) => void | Promise<void>;
102
- }
103
-
104
- // Output Messages
105
- export interface OutputMessage {
106
- /**
107
- * The output text
108
- */
109
- text: string;
110
-
111
- /**
112
- * Timestamp of the output
113
- */
114
- timestamp: number;
115
- }
116
-
117
- // Execution Results
118
- export interface Result {
119
- /**
120
- * Plain text representation
121
- */
122
- text?: string;
123
-
124
- /**
125
- * HTML representation (tables, formatted output)
126
- */
127
- html?: string;
128
-
129
- /**
130
- * PNG image data (base64 encoded)
131
- */
132
- png?: string;
133
-
134
- /**
135
- * JPEG image data (base64 encoded)
136
- */
137
- jpeg?: string;
138
-
139
- /**
140
- * SVG image data
141
- */
142
- svg?: string;
143
-
144
- /**
145
- * LaTeX representation
146
- */
147
- latex?: string;
148
-
149
- /**
150
- * Markdown representation
151
- */
152
- markdown?: string;
153
-
154
- /**
155
- * JavaScript code to execute
156
- */
157
- javascript?: string;
158
-
159
- /**
160
- * JSON data
161
- */
162
- json?: any;
163
-
164
- /**
165
- * Chart data if the result is a visualization
166
- */
167
- chart?: ChartData;
168
-
169
- /**
170
- * Raw data object
171
- */
172
- data?: any;
173
-
174
- /**
175
- * Available output formats
176
- */
177
- formats(): string[];
178
- }
179
-
180
- // Chart Data
181
- export interface ChartData {
182
- /**
183
- * Type of chart
184
- */
185
- type:
186
- | "line"
187
- | "bar"
188
- | "scatter"
189
- | "pie"
190
- | "histogram"
191
- | "heatmap"
192
- | "unknown";
193
-
194
- /**
195
- * Chart title
196
- */
197
- title?: string;
198
-
199
- /**
200
- * Chart data (format depends on library)
201
- */
202
- data: any;
203
-
204
- /**
205
- * Chart layout/configuration
206
- */
207
- layout?: any;
208
-
209
- /**
210
- * Additional configuration
211
- */
212
- config?: any;
213
-
214
- /**
215
- * Library that generated the chart
216
- */
217
- library?: "matplotlib" | "plotly" | "altair" | "seaborn" | "unknown";
218
-
219
- /**
220
- * Base64 encoded image if available
221
- */
222
- image?: string;
223
- }
224
-
225
- // Execution Error
226
- export interface ExecutionError {
227
- /**
228
- * Error name/type (e.g., 'NameError', 'SyntaxError')
229
- */
230
- name: string;
231
-
232
- /**
233
- * Error message
234
- */
235
- value: string;
236
-
237
- /**
238
- * Stack trace
239
- */
240
- traceback: string[];
241
-
242
- /**
243
- * Line number where error occurred
244
- */
245
- lineNumber?: number;
246
- }
247
-
248
- // Serializable execution result
249
- export interface ExecutionResult {
250
- code: string;
251
- logs: {
252
- stdout: string[];
253
- stderr: string[];
254
- };
255
- error?: ExecutionError;
256
- executionCount?: number;
257
- results: Array<{
258
- text?: string;
259
- html?: string;
260
- png?: string;
261
- jpeg?: string;
262
- svg?: string;
263
- latex?: string;
264
- markdown?: string;
265
- javascript?: string;
266
- json?: any;
267
- chart?: ChartData;
268
- data?: any;
269
- }>;
270
- }
271
-
272
- // Execution Result Container
273
- export class Execution {
274
- /**
275
- * All results from the execution
276
- */
277
- public results: Result[] = [];
278
-
279
- /**
280
- * Accumulated stdout and stderr
281
- */
282
- public logs = {
283
- stdout: [] as string[],
284
- stderr: [] as string[],
285
- };
286
-
287
- /**
288
- * Execution error if any
289
- */
290
- public error?: ExecutionError;
291
-
292
- /**
293
- * Execution count (for interpreter)
294
- */
295
- public executionCount?: number;
296
-
297
- constructor(
298
- public readonly code: string,
299
- public readonly context: CodeContext
300
- ) {}
301
-
302
- /**
303
- * Convert to a plain object for serialization
304
- */
305
- toJSON(): ExecutionResult {
306
- return {
307
- code: this.code,
308
- logs: this.logs,
309
- error: this.error,
310
- executionCount: this.executionCount,
311
- results: this.results.map((result) => ({
312
- text: result.text,
313
- html: result.html,
314
- png: result.png,
315
- jpeg: result.jpeg,
316
- svg: result.svg,
317
- latex: result.latex,
318
- markdown: result.markdown,
319
- javascript: result.javascript,
320
- json: result.json,
321
- chart: result.chart,
322
- data: result.data,
323
- })),
324
- };
325
- }
326
- }
327
-
328
- // Implementation of Result
329
- export class ResultImpl implements Result {
330
- constructor(private raw: any) {}
331
-
332
- get text(): string | undefined {
333
- return this.raw.text || this.raw.data?.["text/plain"];
334
- }
335
-
336
- get html(): string | undefined {
337
- return this.raw.html || this.raw.data?.["text/html"];
338
- }
339
-
340
- get png(): string | undefined {
341
- return this.raw.png || this.raw.data?.["image/png"];
342
- }
343
-
344
- get jpeg(): string | undefined {
345
- return this.raw.jpeg || this.raw.data?.["image/jpeg"];
346
- }
347
-
348
- get svg(): string | undefined {
349
- return this.raw.svg || this.raw.data?.["image/svg+xml"];
350
- }
351
-
352
- get latex(): string | undefined {
353
- return this.raw.latex || this.raw.data?.["text/latex"];
354
- }
355
-
356
- get markdown(): string | undefined {
357
- return this.raw.markdown || this.raw.data?.["text/markdown"];
358
- }
359
-
360
- get javascript(): string | undefined {
361
- return this.raw.javascript || this.raw.data?.["application/javascript"];
362
- }
363
-
364
- get json(): any {
365
- return this.raw.json || this.raw.data?.["application/json"];
366
- }
367
-
368
- get chart(): ChartData | undefined {
369
- return this.raw.chart;
370
- }
371
-
372
- get data(): any {
373
- return this.raw.data;
374
- }
375
-
376
- formats(): string[] {
377
- const formats: string[] = [];
378
- if (this.text) formats.push("text");
379
- if (this.html) formats.push("html");
380
- if (this.png) formats.push("png");
381
- if (this.jpeg) formats.push("jpeg");
382
- if (this.svg) formats.push("svg");
383
- if (this.latex) formats.push("latex");
384
- if (this.markdown) formats.push("markdown");
385
- if (this.javascript) formats.push("javascript");
386
- if (this.json) formats.push("json");
387
- if (this.chart) formats.push("chart");
388
- return formats;
389
- }
390
- }