@sandboxxjs/core 0.5.0 → 2.0.0

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 (50) hide show
  1. package/.turbo/turbo-build.log +1 -0
  2. package/CHANGELOG.md +17 -0
  3. package/dist/allocator.d.ts +44 -0
  4. package/dist/allocator.d.ts.map +1 -0
  5. package/dist/allocator.js +14 -0
  6. package/dist/allocator.js.map +1 -0
  7. package/dist/client.d.ts +50 -0
  8. package/dist/client.d.ts.map +1 -0
  9. package/dist/client.js +21 -0
  10. package/dist/client.js.map +1 -0
  11. package/dist/create-client.d.ts +11 -0
  12. package/dist/create-client.d.ts.map +1 -0
  13. package/dist/create-client.js +159 -0
  14. package/dist/create-client.js.map +1 -0
  15. package/dist/index.d.ts +25 -326
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +20 -16858
  18. package/dist/index.js.map +1 -295
  19. package/dist/protocol.d.ts +96 -0
  20. package/dist/protocol.d.ts.map +1 -0
  21. package/dist/protocol.js +15 -0
  22. package/dist/protocol.js.map +1 -0
  23. package/dist/provider.d.ts +54 -0
  24. package/dist/provider.d.ts.map +1 -0
  25. package/dist/provider.js +14 -0
  26. package/dist/provider.js.map +1 -0
  27. package/dist/registry.d.ts +28 -0
  28. package/dist/registry.d.ts.map +1 -0
  29. package/dist/registry.js +19 -0
  30. package/dist/registry.js.map +1 -0
  31. package/dist/router.d.ts +24 -0
  32. package/dist/router.d.ts.map +1 -0
  33. package/dist/router.js +18 -0
  34. package/dist/router.js.map +1 -0
  35. package/dist/sandbox.d.ts +54 -0
  36. package/dist/sandbox.d.ts.map +1 -0
  37. package/dist/sandbox.js +15 -0
  38. package/dist/sandbox.js.map +1 -0
  39. package/package.json +10 -35
  40. package/src/allocator.ts +48 -0
  41. package/src/client.ts +51 -0
  42. package/src/create-client.ts +187 -0
  43. package/src/index.ts +45 -0
  44. package/src/protocol.ts +133 -0
  45. package/src/provider.ts +54 -0
  46. package/src/registry.ts +29 -0
  47. package/src/router.ts +25 -0
  48. package/src/sandbox.ts +52 -0
  49. package/tsconfig.json +12 -0
  50. package/README.md +0 -60
package/dist/index.d.ts CHANGED
@@ -1,327 +1,26 @@
1
- import { WithState, StateLog } from "@sandboxxjs/state";
2
- type IsolatorType = "none" | "srt" | "cloudflare" | "e2b";
3
- type RuntimeType = "node" | "python";
4
- interface StateConfig {
5
- /** Simple environment variable initialization */
6
- env?: Record<string, string>;
7
- /** Initialize state from StateLog */
8
- initializeLog?: StateLog;
9
- /** Enable state recording */
10
- enableRecord?: boolean;
11
- /** Store type (default: resourcex, test: memory) */
12
- store?: "resourcex" | "memory";
13
- }
14
- interface SandboxConfig {
15
- /** Isolator type */
16
- isolator: IsolatorType;
17
- /** Runtime type */
18
- runtime: RuntimeType;
19
- /** Resource limits */
20
- limits?: ResourceLimits;
21
- /** State configuration */
22
- state?: StateConfig;
23
- /** Node-specific configuration */
24
- node?: NodeConfig;
25
- /** Python-specific configuration */
26
- python?: PythonConfig;
27
- }
28
- interface ResourceLimits {
29
- /** Timeout in milliseconds */
30
- timeout?: number;
31
- /** Memory limit in bytes */
32
- memory?: number;
33
- /** CPU limit as percentage */
34
- cpu?: number;
35
- }
36
- interface NodeConfig {
37
- /** Package manager */
38
- packageManager?: "npm" | "yarn" | "pnpm" | "bun";
39
- /** Node version */
40
- version?: string;
41
- }
42
- interface PythonConfig {
43
- /** Python version */
44
- version?: string;
45
- /** Whether to use virtual environment */
46
- useVenv?: boolean;
47
- }
48
1
  /**
49
- * Base Sandbox interface - core APIs
50
- */
51
- interface Sandbox {
52
- /** Unique sandbox ID */
53
- readonly id: string;
54
- /** Execute shell command */
55
- shell(command: string): Promise<ShellResult>;
56
- /** Execute code (script mode - stdout) */
57
- execute(code: string): Promise<ExecuteResult>;
58
- /** Evaluate expression (REPL mode - return value) */
59
- evaluate(expr: string): Promise<EvaluateResult>;
60
- /** Upload file to sandbox */
61
- upload(data: Buffer, remotePath: string): Promise<void>;
62
- /** Download file from sandbox */
63
- download(remotePath: string): Promise<Buffer>;
64
- /** Destroy sandbox */
65
- destroy(): Promise<void>;
66
- }
67
- /**
68
- * Shell execution result
69
- */
70
- interface ShellResult {
71
- /** Whether execution succeeded */
72
- success: boolean;
73
- /** Standard output */
74
- stdout: string;
75
- /** Standard error */
76
- stderr: string;
77
- /** Exit code */
78
- exitCode: number;
79
- /** Execution time in milliseconds */
80
- executionTime: number;
81
- }
82
- /**
83
- * Code execution result (same as ShellResult)
84
- */
85
- interface ExecuteResult {
86
- /** Whether execution succeeded */
87
- success: boolean;
88
- /** Standard output */
89
- stdout: string;
90
- /** Standard error */
91
- stderr: string;
92
- /** Exit code */
93
- exitCode: number;
94
- /** Execution time in milliseconds */
95
- executionTime: number;
96
- }
97
- /**
98
- * Expression evaluation result
99
- */
100
- interface EvaluateResult {
101
- /** Expression result value (as string) */
102
- value: string;
103
- /** Execution time in milliseconds */
104
- executionTime: number;
105
- }
106
- /** Sandbox with State (fs, env, storage) */
107
- type StateSandbox = Sandbox & WithState;
108
- /** Sandbox constructor type */
109
- type SandboxConstructor<T extends Sandbox = Sandbox> = new (config: SandboxConfig) => T;
110
- interface IsolatorOptions {
111
- timeout?: number;
112
- env?: Record<string, string>;
113
- }
114
- declare abstract class Isolator {
115
- protected runtime: RuntimeType;
116
- constructor(runtime: RuntimeType);
117
- /**
118
- * Execute code (script mode - stdout)
119
- * Command depends on runtime: node -e / python3 -c
120
- */
121
- abstract execute(code: string, options?: IsolatorOptions): Promise<ExecuteResult>;
122
- /**
123
- * Evaluate expression (REPL mode - return value)
124
- * Command depends on runtime: node -p / python3 -c 'print(...)'
125
- */
126
- abstract evaluate(expr: string, options?: IsolatorOptions): Promise<EvaluateResult>;
127
- /**
128
- * Upload file to isolated environment
129
- */
130
- abstract upload(data: Buffer, remotePath: string): Promise<void>;
131
- /**
132
- * Download file from isolated environment
133
- */
134
- abstract download(remotePath: string): Promise<Buffer>;
135
- /**
136
- * Destroy isolator and cleanup resources
137
- */
138
- abstract destroy(): Promise<void>;
139
- }
140
- declare class BaseSandbox implements Sandbox {
141
- readonly id: string;
142
- protected isolator: Isolator;
143
- protected config: SandboxConfig;
144
- constructor(config: SandboxConfig);
145
- private createIsolator;
146
- /**
147
- * Execute shell command
148
- */
149
- shell(command: string): Promise<ShellResult>;
150
- /**
151
- * Execute code (script mode)
152
- */
153
- execute(code: string): Promise<ExecuteResult>;
154
- /**
155
- * Evaluate expression (REPL mode)
156
- */
157
- evaluate(expr: string): Promise<EvaluateResult>;
158
- /**
159
- * Upload file to sandbox
160
- */
161
- upload(data: Buffer, remotePath: string): Promise<void>;
162
- /**
163
- * Download file from sandbox
164
- */
165
- download(remotePath: string): Promise<Buffer>;
166
- /**
167
- * Destroy sandbox and cleanup resources
168
- */
169
- destroy(): Promise<void>;
170
- }
171
- declare class NoneIsolator extends Isolator {
172
- private workDir;
173
- constructor(runtime: RuntimeType);
174
- /**
175
- * Execute shell command
176
- */
177
- shell(command: string, options?: IsolatorOptions): Promise<ShellResult>;
178
- /**
179
- * Execute code (script mode)
180
- */
181
- execute(code: string, options?: IsolatorOptions): Promise<ExecuteResult>;
182
- /**
183
- * Evaluate expression (REPL mode)
184
- */
185
- evaluate(expr: string, options?: IsolatorOptions): Promise<EvaluateResult>;
186
- /**
187
- * Build execute command based on runtime
188
- */
189
- private buildExecuteCommand;
190
- /**
191
- * Build evaluate command based on runtime
192
- */
193
- private buildEvaluateCommand;
194
- /**
195
- * Run command in work directory
196
- */
197
- private runCommand;
198
- /**
199
- * Upload file to sandbox
200
- */
201
- upload(data: Buffer, remotePath: string): Promise<void>;
202
- /**
203
- * Download file from sandbox
204
- */
205
- download(remotePath: string): Promise<Buffer>;
206
- /**
207
- * Destroy isolator and cleanup
208
- */
209
- destroy(): Promise<void>;
210
- }
211
- declare class SrtIsolator extends Isolator {
212
- private workDir;
213
- private initialized;
214
- constructor(runtime: RuntimeType);
215
- /**
216
- * Initialize SandboxManager if not already initialized
217
- */
218
- private ensureInitialized;
219
- /**
220
- * Execute shell command with srt isolation
221
- */
222
- shell(command: string, options?: IsolatorOptions): Promise<ShellResult>;
223
- /**
224
- * Execute code (script mode) with srt isolation
225
- */
226
- execute(code: string, options?: IsolatorOptions): Promise<ExecuteResult>;
227
- /**
228
- * Evaluate expression (REPL mode) with srt isolation
229
- */
230
- evaluate(expr: string, options?: IsolatorOptions): Promise<EvaluateResult>;
231
- /**
232
- * Build execute command based on runtime
233
- */
234
- private buildExecuteCommand;
235
- /**
236
- * Build evaluate command based on runtime
237
- */
238
- private buildEvaluateCommand;
239
- /**
240
- * Run command with srt sandbox wrapper
241
- */
242
- private runCommand;
243
- /**
244
- * Upload file to sandbox
245
- */
246
- upload(data: Buffer, remotePath: string): Promise<void>;
247
- /**
248
- * Download file from sandbox
249
- */
250
- download(remotePath: string): Promise<Buffer>;
251
- /**
252
- * Destroy isolator and cleanup
253
- */
254
- destroy(): Promise<void>;
255
- }
256
- declare class CloudflareContainerIsolator extends Isolator {
257
- private serverProcess?;
258
- private serverUrl?;
259
- private isReady;
260
- constructor(runtime: RuntimeType);
261
- /**
262
- * Find an available port
263
- */
264
- private findFreePort;
265
- /**
266
- * Get binary path from installed package
267
- */
268
- private getBinaryPath;
269
- /**
270
- * Wait for server to be ready
271
- */
272
- private waitForReady;
273
- /**
274
- * Ensure server is running
275
- */
276
- private ensureServerRunning;
277
- /**
278
- * Execute shell command
279
- */
280
- shell(command: string, options?: IsolatorOptions): Promise<ShellResult>;
281
- /**
282
- * Execute code (script mode)
283
- */
284
- execute(code: string, options?: IsolatorOptions): Promise<ExecuteResult>;
285
- /**
286
- * Evaluate expression (REPL mode)
287
- */
288
- evaluate(expr: string, options?: IsolatorOptions): Promise<EvaluateResult>;
289
- /**
290
- * Call server to execute command
291
- */
292
- private callServer;
293
- /**
294
- * Upload file to sandbox
295
- */
296
- upload(_data: Buffer, _remotePath: string): Promise<void>;
297
- /**
298
- * Download file from sandbox
299
- */
300
- download(_remotePath: string): Promise<Buffer>;
301
- /**
302
- * Destroy isolator and cleanup
303
- */
304
- destroy(): Promise<void>;
305
- }
306
- import { StateFS, StateEnv, StateStorage, buildStateLog, loadStateLog, StateLog as StateLog2, StateLogEntry, FileSystem, Environment, Storage, WithState as WithState3, StateError, FileSystemError } from "@sandboxxjs/state";
307
- import { WithState as WithState2 } from "@sandboxxjs/state";
308
- /**
309
- * Add state capabilities to sandbox
310
- */
311
- declare function withState<T extends Sandbox>(Base: SandboxConstructor<T>): SandboxConstructor<T & WithState2>;
312
- /**
313
- * Error types for SandboX
314
- */
315
- declare class SandboxError extends Error {
316
- constructor(message: string);
317
- }
318
- declare class ExecutionError extends SandboxError {
319
- constructor(message: string);
320
- }
321
- declare class TimeoutError extends SandboxError {
322
- constructor(message: string);
323
- }
324
- declare class IsolationError extends SandboxError {
325
- constructor(message: string);
326
- }
327
- export { withState, loadStateLog, buildStateLog, WithState3 as WithState, TimeoutError, Storage, StateStorage, StateSandbox, StateLogEntry, StateLog2 as StateLog, StateFS, StateError, StateEnv, StateConfig, SrtIsolator, ShellResult, SandboxError, SandboxConstructor, SandboxConfig, Sandbox, RuntimeType, ResourceLimits, PythonConfig, NoneIsolator, NodeConfig, IsolatorType, Isolator, IsolationError, FileSystemError, FileSystem, ExecutionError, ExecuteResult, EvaluateResult, Environment, CloudflareContainerIsolator, BaseSandbox };
2
+ * @sandboxxjs/core Sandbox abstraction framework.
3
+ *
4
+ * Unified lifecycle for any sandbox environment:
5
+ *
6
+ * Allocate → Prepare → Register → Ready → Command
7
+ *
8
+ * 1. Allocator provisions resources, returns SandboxContainer (status: pending)
9
+ * 2. Sandbox environment starts, sandbox-client prepares
10
+ * 3. sandbox-client connects to Registry via WebSocket, registers
11
+ * 4. Registry marks sandbox as ready
12
+ * 5. Router dispatches commands through Registry to sandbox-client
13
+ *
14
+ * Platform differences are injected via SandboxProvider:
15
+ * - @sandboxxjs/node-provider: child_process + node:fs
16
+ * - @sandboxxjs/web-provider: @webcontainer/api
17
+ * - Future: Docker, SSH, WASM, etc.
18
+ */
19
+ export type { AllocateRequest, SandboxAllocator, SandboxContainer, SandboxContainerType, SandboxStatus, } from "./allocator";
20
+ export type { SandboxClient, SandboxClientOptions } from "./client";
21
+ export { createSandboxClient } from "./create-client";
22
+ export type { SandboxExecutor, SandboxFileSystem, SandboxProcessManager, SandboxProvider, } from "./provider";
23
+ export type { SandboxConnection, SandboxRegistry } from "./registry";
24
+ export type { SandboxRouter } from "./router";
25
+ export type { ExecOptions, ExecResult, FileInfo, ProcessInfo, Sandbox } from "./sandbox";
26
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,YAAY,EACV,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,oBAAoB,EACpB,aAAa,GACd,MAAM,aAAa,CAAC;AAGrB,YAAY,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEtD,YAAY,EACV,eAAe,EACf,iBAAiB,EACjB,qBAAqB,EACrB,eAAe,GAChB,MAAM,YAAY,CAAC;AAEpB,YAAY,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAErE,YAAY,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAG9C,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC"}