@cloudflare/sandbox 0.0.0-44e584c → 0.0.0-485cf61

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 (79) hide show
  1. package/CHANGELOG.md +185 -0
  2. package/Dockerfile +160 -9
  3. package/README.md +149 -50
  4. package/dist/chunk-3NEP4CNV.js +99 -0
  5. package/dist/chunk-3NEP4CNV.js.map +1 -0
  6. package/dist/chunk-6IYG2RIN.js +117 -0
  7. package/dist/chunk-6IYG2RIN.js.map +1 -0
  8. package/dist/chunk-HB44YO2A.js +2331 -0
  9. package/dist/chunk-HB44YO2A.js.map +1 -0
  10. package/dist/chunk-KPVMMMIP.js +105 -0
  11. package/dist/chunk-KPVMMMIP.js.map +1 -0
  12. package/dist/chunk-NNGBXDMY.js +89 -0
  13. package/dist/chunk-NNGBXDMY.js.map +1 -0
  14. package/dist/file-stream.d.ts +43 -0
  15. package/dist/file-stream.js +9 -0
  16. package/dist/file-stream.js.map +1 -0
  17. package/dist/index.d.ts +9 -0
  18. package/dist/index.js +55 -0
  19. package/dist/index.js.map +1 -0
  20. package/dist/interpreter.d.ts +33 -0
  21. package/dist/interpreter.js +8 -0
  22. package/dist/interpreter.js.map +1 -0
  23. package/dist/request-handler.d.ts +18 -0
  24. package/dist/request-handler.js +12 -0
  25. package/dist/request-handler.js.map +1 -0
  26. package/dist/sandbox-CtlKjZwf.d.ts +583 -0
  27. package/dist/sandbox.d.ts +4 -0
  28. package/dist/sandbox.js +12 -0
  29. package/dist/sandbox.js.map +1 -0
  30. package/dist/security.d.ts +35 -0
  31. package/dist/security.js +15 -0
  32. package/dist/security.js.map +1 -0
  33. package/dist/sse-parser.d.ts +28 -0
  34. package/dist/sse-parser.js +11 -0
  35. package/dist/sse-parser.js.map +1 -0
  36. package/package.json +11 -9
  37. package/src/clients/base-client.ts +297 -0
  38. package/src/clients/command-client.ts +118 -0
  39. package/src/clients/file-client.ts +272 -0
  40. package/src/clients/git-client.ts +95 -0
  41. package/src/clients/index.ts +63 -0
  42. package/src/clients/interpreter-client.ts +332 -0
  43. package/src/clients/port-client.ts +108 -0
  44. package/src/clients/process-client.ts +180 -0
  45. package/src/clients/sandbox-client.ts +41 -0
  46. package/src/clients/types.ts +81 -0
  47. package/src/clients/utility-client.ts +97 -0
  48. package/src/errors/adapter.ts +180 -0
  49. package/src/errors/classes.ts +469 -0
  50. package/src/errors/index.ts +105 -0
  51. package/src/file-stream.ts +164 -0
  52. package/src/index.ts +83 -119
  53. package/src/interpreter.ts +159 -0
  54. package/src/request-handler.ts +198 -0
  55. package/src/sandbox.ts +959 -0
  56. package/src/security.ts +133 -0
  57. package/src/sse-parser.ts +147 -0
  58. package/startup.sh +7 -0
  59. package/tests/base-client.test.ts +328 -0
  60. package/tests/command-client.test.ts +407 -0
  61. package/tests/file-client.test.ts +643 -0
  62. package/tests/file-stream.test.ts +306 -0
  63. package/tests/git-client.test.ts +328 -0
  64. package/tests/port-client.test.ts +301 -0
  65. package/tests/process-client.test.ts +658 -0
  66. package/tests/sandbox.test.ts +465 -0
  67. package/tests/sse-parser.test.ts +291 -0
  68. package/tests/utility-client.test.ts +266 -0
  69. package/tests/wrangler.jsonc +35 -0
  70. package/tsconfig.json +9 -1
  71. package/vitest.config.ts +31 -0
  72. package/container_src/index.ts +0 -2906
  73. package/container_src/package.json +0 -9
  74. package/src/client.ts +0 -1950
  75. package/tests/client.example.ts +0 -308
  76. package/tests/connection-test.ts +0 -81
  77. package/tests/simple-test.ts +0 -81
  78. package/tests/test1.ts +0 -281
  79. package/tests/test2.ts +0 -929
@@ -0,0 +1,43 @@
1
+ import { FileChunk, FileMetadata } from '@repo/shared';
2
+
3
+ /**
4
+ * Stream a file from the sandbox with automatic base64 decoding for binary files
5
+ *
6
+ * @param stream - The ReadableStream from readFileStream()
7
+ * @returns AsyncGenerator that yields FileChunk (string for text, Uint8Array for binary)
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * const stream = await sandbox.readFileStream('/path/to/file.png');
12
+ * for await (const chunk of streamFile(stream)) {
13
+ * if (chunk instanceof Uint8Array) {
14
+ * // Binary chunk
15
+ * console.log('Binary chunk:', chunk.length, 'bytes');
16
+ * } else {
17
+ * // Text chunk
18
+ * console.log('Text chunk:', chunk);
19
+ * }
20
+ * }
21
+ * ```
22
+ */
23
+ declare function streamFile(stream: ReadableStream<Uint8Array>): AsyncGenerator<FileChunk, FileMetadata>;
24
+ /**
25
+ * Collect an entire file into memory from a stream
26
+ *
27
+ * @param stream - The ReadableStream from readFileStream()
28
+ * @returns Object containing the file content and metadata
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * const stream = await sandbox.readFileStream('/path/to/file.txt');
33
+ * const { content, metadata } = await collectFile(stream);
34
+ * console.log('Content:', content);
35
+ * console.log('MIME type:', metadata.mimeType);
36
+ * ```
37
+ */
38
+ declare function collectFile(stream: ReadableStream<Uint8Array>): Promise<{
39
+ content: string | Uint8Array;
40
+ metadata: FileMetadata;
41
+ }>;
42
+
43
+ export { collectFile, streamFile };
@@ -0,0 +1,9 @@
1
+ import {
2
+ collectFile,
3
+ streamFile
4
+ } from "./chunk-KPVMMMIP.js";
5
+ export {
6
+ collectFile,
7
+ streamFile
8
+ };
9
+ //# sourceMappingURL=file-stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,9 @@
1
+ export { B as BaseApiResponse, C as CommandClient, f as CommandExecuteResponse, c as CommandsResponse, d as ContainerStub, E as ErrorResponse, e as ExecuteRequest, p as ExecutionCallbacks, h as ExposePortRequest, F as FileClient, i as FileOperationRequest, j as GitCheckoutRequest, G as GitClient, I as InterpreterClient, M as MkdirRequest, k as PingResponse, P as PortClient, a as ProcessClient, R as ReadFileRequest, l as RequestConfig, m as ResponseHandler, b as Sandbox, S as SandboxClient, H as SandboxClientOptions, n as SessionRequest, o as UnexposePortRequest, U as UtilityClient, W as WriteFileRequest, g as getSandbox } from './sandbox-CtlKjZwf.js';
2
+ export * from '@repo/shared';
3
+ export { BaseExecOptions, ExecEvent, ExecOptions, ExecResult, FileChunk, FileMetadata, FileStreamEvent, GitCheckoutResult, ISandbox, LogEvent, PortCloseResult, PortExposeResult, PortListResult, Process, ProcessCleanupResult, ProcessInfoResult, ProcessKillResult, ProcessListResult, ProcessLogsResult, ProcessOptions, ProcessStartResult, ProcessStatus, StartProcessRequest, StreamOptions, isExecResult, isProcess, isProcessStatus } from '@repo/shared';
4
+ export { collectFile, streamFile } from './file-stream.js';
5
+ export { CodeInterpreter } from './interpreter.js';
6
+ export { RouteInfo, SandboxEnv, proxyToSandbox } from './request-handler.js';
7
+ export { asyncIterableToSSEStream, parseSSEStream, responseToAsyncIterable } from './sse-parser.js';
8
+ import 'cloudflare:workers';
9
+ import '@cloudflare/containers';
package/dist/index.js ADDED
@@ -0,0 +1,55 @@
1
+ import {
2
+ collectFile,
3
+ streamFile
4
+ } from "./chunk-KPVMMMIP.js";
5
+ import {
6
+ CommandClient,
7
+ FileClient,
8
+ GitClient,
9
+ PortClient,
10
+ ProcessClient,
11
+ Sandbox,
12
+ SandboxClient,
13
+ UtilityClient,
14
+ getSandbox,
15
+ proxyToSandbox
16
+ } from "./chunk-HB44YO2A.js";
17
+ import {
18
+ CodeInterpreter
19
+ } from "./chunk-6IYG2RIN.js";
20
+ import "./chunk-3NEP4CNV.js";
21
+ import {
22
+ asyncIterableToSSEStream,
23
+ parseSSEStream,
24
+ responseToAsyncIterable
25
+ } from "./chunk-NNGBXDMY.js";
26
+
27
+ // src/index.ts
28
+ export * from "@repo/shared";
29
+ import {
30
+ isExecResult,
31
+ isProcess,
32
+ isProcessStatus
33
+ } from "@repo/shared";
34
+ export {
35
+ CodeInterpreter,
36
+ CommandClient,
37
+ FileClient,
38
+ GitClient,
39
+ PortClient,
40
+ ProcessClient,
41
+ Sandbox,
42
+ SandboxClient,
43
+ UtilityClient,
44
+ asyncIterableToSSEStream,
45
+ collectFile,
46
+ getSandbox,
47
+ isExecResult,
48
+ isProcess,
49
+ isProcessStatus,
50
+ parseSSEStream,
51
+ proxyToSandbox,
52
+ responseToAsyncIterable,
53
+ streamFile
54
+ };
55
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["// Export the main Sandbox class and utilities\n\n\n// Export the new client architecture\nexport {\n CommandClient,\n FileClient,\n GitClient,\n PortClient,\n ProcessClient,\n SandboxClient,\n UtilityClient\n} from \"./clients\";\nexport { getSandbox, Sandbox } from \"./sandbox\";\n\n// Legacy types are now imported from the new client architecture\n\n// Export core SDK types for consumers\nexport type {\n BaseExecOptions,\n ExecEvent,\n ExecOptions,\n ExecResult,FileChunk, FileMetadata, FileStreamEvent, \n ISandbox,\n LogEvent,\n Process,\n ProcessOptions,\n ProcessStatus,\n StreamOptions \n} from \"@repo/shared\";\nexport * from '@repo/shared';\n// Export type guards for runtime validation\nexport {\n isExecResult,\n isProcess,\n isProcessStatus\n} from \"@repo/shared\";\n// Export all client types from new architecture\nexport type {\n BaseApiResponse,\n CommandsResponse,\n ContainerStub,\n ErrorResponse,\n\n // Command client types\n ExecuteRequest,\n ExecuteResponse as CommandExecuteResponse,\n\n // Port client types\n ExposePortRequest,\n FileOperationRequest,\n\n // Git client types\n GitCheckoutRequest,\n GitCheckoutResult,\n // Base client types\n HttpClientOptions as SandboxClientOptions,\n\n // File client types\n MkdirRequest,\n\n // Utility client types\n PingResponse,\n PortCloseResult,\n PortExposeResult,\n PortListResult,\n ProcessCleanupResult,\n ProcessInfoResult,\n ProcessKillResult,\n ProcessListResult,\n ProcessLogsResult,\n ProcessStartResult,\n ReadFileRequest,\n RequestConfig,\n ResponseHandler,\n SessionRequest,\n\n // Process client types\n StartProcessRequest,\n UnexposePortRequest,\n WriteFileRequest\n} from \"./clients\";\nexport type { ExecutionCallbacks, InterpreterClient } from './clients/interpreter-client.js';\n// Export file streaming utilities for binary file support\nexport { collectFile, streamFile } from './file-stream';\n// Export interpreter functionality\nexport { CodeInterpreter } from './interpreter.js';\n// Re-export request handler utilities\nexport {\n proxyToSandbox, type RouteInfo, type SandboxEnv\n} from './request-handler';\n// Export SSE parser for converting ReadableStream to AsyncIterable\nexport { asyncIterableToSSEStream, parseSSEStream, responseToAsyncIterable } from \"./sse-parser\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA8BA,cAAc;AAEd;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;","names":[]}
@@ -0,0 +1,33 @@
1
+ import { CreateContextOptions, CodeContext, RunCodeOptions, Execution } from '@repo/shared';
2
+ import { b as Sandbox } from './sandbox-CtlKjZwf.js';
3
+ import 'cloudflare:workers';
4
+ import '@cloudflare/containers';
5
+
6
+ declare class CodeInterpreter {
7
+ private interpreterClient;
8
+ private contexts;
9
+ constructor(sandbox: Sandbox);
10
+ /**
11
+ * Create a new code execution context
12
+ */
13
+ createCodeContext(options?: CreateContextOptions): Promise<CodeContext>;
14
+ /**
15
+ * Run code with optional context
16
+ */
17
+ runCode(code: string, options?: RunCodeOptions): Promise<Execution>;
18
+ /**
19
+ * Run code and return a streaming response
20
+ */
21
+ runCodeStream(code: string, options?: RunCodeOptions): Promise<ReadableStream>;
22
+ /**
23
+ * List all code contexts
24
+ */
25
+ listCodeContexts(): Promise<CodeContext[]>;
26
+ /**
27
+ * Delete a code context
28
+ */
29
+ deleteCodeContext(contextId: string): Promise<void>;
30
+ private getOrCreateDefaultContext;
31
+ }
32
+
33
+ export { CodeInterpreter };
@@ -0,0 +1,8 @@
1
+ import {
2
+ CodeInterpreter
3
+ } from "./chunk-6IYG2RIN.js";
4
+ import "./chunk-3NEP4CNV.js";
5
+ export {
6
+ CodeInterpreter
7
+ };
8
+ //# sourceMappingURL=interpreter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,18 @@
1
+ import { b as Sandbox } from './sandbox-CtlKjZwf.js';
2
+ import '@repo/shared';
3
+ import 'cloudflare:workers';
4
+ import '@cloudflare/containers';
5
+
6
+ interface SandboxEnv {
7
+ Sandbox: DurableObjectNamespace<Sandbox>;
8
+ }
9
+ interface RouteInfo {
10
+ port: number;
11
+ sandboxId: string;
12
+ path: string;
13
+ token: string;
14
+ }
15
+ declare function proxyToSandbox<E extends SandboxEnv>(request: Request, env: E): Promise<Response | null>;
16
+ declare function isLocalhostPattern(hostname: string): boolean;
17
+
18
+ export { type RouteInfo, type SandboxEnv, isLocalhostPattern, proxyToSandbox };
@@ -0,0 +1,12 @@
1
+ import {
2
+ isLocalhostPattern,
3
+ proxyToSandbox
4
+ } from "./chunk-HB44YO2A.js";
5
+ import "./chunk-6IYG2RIN.js";
6
+ import "./chunk-3NEP4CNV.js";
7
+ import "./chunk-NNGBXDMY.js";
8
+ export {
9
+ isLocalhostPattern,
10
+ proxyToSandbox
11
+ };
12
+ //# sourceMappingURL=request-handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}