@sandboxxjs/core 0.4.0 → 0.5.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.
- package/dist/index.d.ts +122 -36
- package/dist/index.js +8398 -230
- package/dist/index.js.map +141 -11
- package/package.json +4 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { WithState, StateLog } from "@sandboxxjs/state";
|
|
2
|
-
type IsolatorType = "
|
|
3
|
-
type
|
|
2
|
+
type IsolatorType = "none" | "srt" | "cloudflare" | "e2b";
|
|
3
|
+
type RuntimeType = "node" | "python";
|
|
4
4
|
interface StateConfig {
|
|
5
5
|
/** Simple environment variable initialization */
|
|
6
6
|
env?: Record<string, string>;
|
|
@@ -14,8 +14,8 @@ interface StateConfig {
|
|
|
14
14
|
interface SandboxConfig {
|
|
15
15
|
/** Isolator type */
|
|
16
16
|
isolator: IsolatorType;
|
|
17
|
-
/** Runtime type
|
|
18
|
-
runtime
|
|
17
|
+
/** Runtime type */
|
|
18
|
+
runtime: RuntimeType;
|
|
19
19
|
/** Resource limits */
|
|
20
20
|
limits?: ResourceLimits;
|
|
21
21
|
/** State configuration */
|
|
@@ -46,13 +46,17 @@ interface PythonConfig {
|
|
|
46
46
|
useVenv?: boolean;
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
49
|
-
* Base Sandbox interface -
|
|
49
|
+
* Base Sandbox interface - core APIs
|
|
50
50
|
*/
|
|
51
51
|
interface Sandbox {
|
|
52
52
|
/** Unique sandbox ID */
|
|
53
53
|
readonly id: string;
|
|
54
54
|
/** Execute shell command */
|
|
55
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>;
|
|
56
60
|
/** Upload file to sandbox */
|
|
57
61
|
upload(data: Buffer, remotePath: string): Promise<void>;
|
|
58
62
|
/** Download file from sandbox */
|
|
@@ -76,11 +80,8 @@ interface ShellResult {
|
|
|
76
80
|
executionTime: number;
|
|
77
81
|
}
|
|
78
82
|
/**
|
|
79
|
-
* Code execution
|
|
83
|
+
* Code execution result (same as ShellResult)
|
|
80
84
|
*/
|
|
81
|
-
interface WithExecute {
|
|
82
|
-
execute(code: string): Promise<ExecuteResult>;
|
|
83
|
-
}
|
|
84
85
|
interface ExecuteResult {
|
|
85
86
|
/** Whether execution succeeded */
|
|
86
87
|
success: boolean;
|
|
@@ -93,28 +94,36 @@ interface ExecuteResult {
|
|
|
93
94
|
/** Execution time in milliseconds */
|
|
94
95
|
executionTime: number;
|
|
95
96
|
}
|
|
96
|
-
/**
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
/**
|
|
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) */
|
|
101
107
|
type StateSandbox = Sandbox & WithState;
|
|
102
108
|
/** Sandbox constructor type */
|
|
103
109
|
type SandboxConstructor<T extends Sandbox = Sandbox> = new (config: SandboxConfig) => T;
|
|
104
|
-
|
|
105
|
-
type SandboxMixin<
|
|
106
|
-
T extends Sandbox,
|
|
107
|
-
U
|
|
108
|
-
> = (Base: SandboxConstructor<T>) => SandboxConstructor<T & U>;
|
|
109
|
-
interface ShellOptions {
|
|
110
|
+
interface IsolatorOptions {
|
|
110
111
|
timeout?: number;
|
|
111
112
|
env?: Record<string, string>;
|
|
112
113
|
}
|
|
113
114
|
declare abstract class Isolator {
|
|
115
|
+
protected runtime: RuntimeType;
|
|
116
|
+
constructor(runtime: RuntimeType);
|
|
114
117
|
/**
|
|
115
|
-
* Execute
|
|
118
|
+
* Execute code (script mode - stdout)
|
|
119
|
+
* Command depends on runtime: node -e / python3 -c
|
|
116
120
|
*/
|
|
117
|
-
abstract
|
|
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>;
|
|
118
127
|
/**
|
|
119
128
|
* Upload file to isolated environment
|
|
120
129
|
*/
|
|
@@ -139,6 +148,14 @@ declare class BaseSandbox implements Sandbox {
|
|
|
139
148
|
*/
|
|
140
149
|
shell(command: string): Promise<ShellResult>;
|
|
141
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
|
+
/**
|
|
142
159
|
* Upload file to sandbox
|
|
143
160
|
*/
|
|
144
161
|
upload(data: Buffer, remotePath: string): Promise<void>;
|
|
@@ -151,13 +168,78 @@ declare class BaseSandbox implements Sandbox {
|
|
|
151
168
|
*/
|
|
152
169
|
destroy(): Promise<void>;
|
|
153
170
|
}
|
|
154
|
-
declare class
|
|
171
|
+
declare class NoneIsolator extends Isolator {
|
|
155
172
|
private workDir;
|
|
156
|
-
constructor();
|
|
173
|
+
constructor(runtime: RuntimeType);
|
|
157
174
|
/**
|
|
158
175
|
* Execute shell command
|
|
159
176
|
*/
|
|
160
|
-
shell(command: string, options?:
|
|
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;
|
|
161
243
|
/**
|
|
162
244
|
* Upload file to sandbox
|
|
163
245
|
*/
|
|
@@ -175,7 +257,7 @@ declare class CloudflareContainerIsolator extends Isolator {
|
|
|
175
257
|
private serverProcess?;
|
|
176
258
|
private serverUrl?;
|
|
177
259
|
private isReady;
|
|
178
|
-
constructor();
|
|
260
|
+
constructor(runtime: RuntimeType);
|
|
179
261
|
/**
|
|
180
262
|
* Find an available port
|
|
181
263
|
*/
|
|
@@ -195,7 +277,19 @@ declare class CloudflareContainerIsolator extends Isolator {
|
|
|
195
277
|
/**
|
|
196
278
|
* Execute shell command
|
|
197
279
|
*/
|
|
198
|
-
shell(command: string, options?:
|
|
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;
|
|
199
293
|
/**
|
|
200
294
|
* Upload file to sandbox
|
|
201
295
|
*/
|
|
@@ -216,14 +310,6 @@ import { WithState as WithState2 } from "@sandboxxjs/state";
|
|
|
216
310
|
*/
|
|
217
311
|
declare function withState<T extends Sandbox>(Base: SandboxConstructor<T>): SandboxConstructor<T & WithState2>;
|
|
218
312
|
/**
|
|
219
|
-
* Add Node.js execute capability to sandbox
|
|
220
|
-
*/
|
|
221
|
-
declare function withNodeExecute<T extends Sandbox>(Base: SandboxConstructor<T>): SandboxConstructor<T & WithExecute>;
|
|
222
|
-
/**
|
|
223
|
-
* Add Python execute capability to sandbox
|
|
224
|
-
*/
|
|
225
|
-
declare function withPythonExecute<T extends Sandbox>(Base: SandboxConstructor<T>): SandboxConstructor<T & WithExecute>;
|
|
226
|
-
/**
|
|
227
313
|
* Error types for SandboX
|
|
228
314
|
*/
|
|
229
315
|
declare class SandboxError extends Error {
|
|
@@ -238,4 +324,4 @@ declare class TimeoutError extends SandboxError {
|
|
|
238
324
|
declare class IsolationError extends SandboxError {
|
|
239
325
|
constructor(message: string);
|
|
240
326
|
}
|
|
241
|
-
export { withState,
|
|
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 };
|