@sandboxxjs/core 0.1.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/README.md +60 -0
- package/dist/index.d.ts +135 -0
- package/dist/index.js +7565 -0
- package/dist/index.js.map +161 -0
- package/package.json +48 -0
package/README.md
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# @@sandboxxjs/sandbox/core
|
|
2
|
+
|
|
3
|
+
Core implementation for SandboX - secure code execution engine.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Multiple isolators (Local, Cloudflare, E2B, Firecracker)
|
|
8
|
+
- Multiple runtimes (Node.js, Python, Bash, Docker)
|
|
9
|
+
- File system operations
|
|
10
|
+
- Resource limits
|
|
11
|
+
- Event-driven architecture
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npm install @@sandboxxjs/sandbox/core
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
```typescript
|
|
22
|
+
import { Sandbox, LocalIsolator } from "@@sandboxxjs/sandbox/core";
|
|
23
|
+
|
|
24
|
+
const isolator = new LocalIsolator("node");
|
|
25
|
+
const sandbox = new Sandbox({
|
|
26
|
+
runtime: "node",
|
|
27
|
+
isolator: "local",
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const result = await sandbox.execute({
|
|
31
|
+
code: 'console.log("Hello")',
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
console.log(result.stdout); // "Hello"
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## API
|
|
38
|
+
|
|
39
|
+
### Sandbox
|
|
40
|
+
|
|
41
|
+
```typescript
|
|
42
|
+
class Sandbox {
|
|
43
|
+
execute(options: ExecuteOptions): Promise<ExecuteResult>;
|
|
44
|
+
writeFile(path: string, data: string): Promise<void>;
|
|
45
|
+
readFile(path: string): Promise<string>;
|
|
46
|
+
destroy(): Promise<void>;
|
|
47
|
+
on(event: string, handler: Function): void;
|
|
48
|
+
fs: FileSystem;
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Isolators
|
|
53
|
+
|
|
54
|
+
- `LocalIsolator` - Process isolation via execa
|
|
55
|
+
- `CloudflareContainerIsolator` - Docker via Bun binary
|
|
56
|
+
- `E2BIsolator` - E2B microVM (not yet implemented)
|
|
57
|
+
|
|
58
|
+
## License
|
|
59
|
+
|
|
60
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core type definitions for SandboX
|
|
3
|
+
*/
|
|
4
|
+
type Runtime = "bash" | "node" | "python" | "docker";
|
|
5
|
+
type IsolatorType = "local" | "cloudflare" | "e2b" | "firecracker" | "docker";
|
|
6
|
+
interface SandboxConfig {
|
|
7
|
+
runtime: Runtime;
|
|
8
|
+
isolator: IsolatorType;
|
|
9
|
+
limits?: ResourceLimits;
|
|
10
|
+
isolation?: IsolationConfig;
|
|
11
|
+
}
|
|
12
|
+
interface ResourceLimits {
|
|
13
|
+
timeout?: number;
|
|
14
|
+
memory?: number;
|
|
15
|
+
cpu?: number;
|
|
16
|
+
}
|
|
17
|
+
interface IsolationConfig {
|
|
18
|
+
networkAccess?: boolean;
|
|
19
|
+
fileSystemAccess?: boolean;
|
|
20
|
+
envVars?: Record<string, string>;
|
|
21
|
+
}
|
|
22
|
+
interface ExecuteOptions {
|
|
23
|
+
code: string;
|
|
24
|
+
env?: Record<string, string>;
|
|
25
|
+
timeout?: number;
|
|
26
|
+
}
|
|
27
|
+
interface ExecuteResult {
|
|
28
|
+
success: boolean;
|
|
29
|
+
data?: unknown;
|
|
30
|
+
stdout?: string;
|
|
31
|
+
stderr?: string;
|
|
32
|
+
error?: string;
|
|
33
|
+
exitCode?: number;
|
|
34
|
+
metadata: {
|
|
35
|
+
executionTime: number
|
|
36
|
+
timestamp: string
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
interface FileSystem {
|
|
40
|
+
write(path: string, data: string): Promise<void>;
|
|
41
|
+
read(path: string): Promise<string>;
|
|
42
|
+
list(path: string): Promise<string[]>;
|
|
43
|
+
delete(path: string): Promise<void>;
|
|
44
|
+
exists(path: string): Promise<boolean>;
|
|
45
|
+
}
|
|
46
|
+
type EventHandler = (...args: unknown[]) => void;
|
|
47
|
+
declare class Sandbox {
|
|
48
|
+
private isolator;
|
|
49
|
+
private runtime;
|
|
50
|
+
private eventHandlers;
|
|
51
|
+
fs: FileSystem;
|
|
52
|
+
constructor(config: SandboxConfig);
|
|
53
|
+
private createIsolator;
|
|
54
|
+
private createRuntime;
|
|
55
|
+
execute(options: ExecuteOptions): Promise<ExecuteResult>;
|
|
56
|
+
writeFile(filePath: string, data: string): Promise<void>;
|
|
57
|
+
readFile(filePath: string): Promise<string>;
|
|
58
|
+
destroy(): Promise<void>;
|
|
59
|
+
on(event: string, handler: EventHandler): void;
|
|
60
|
+
private emit;
|
|
61
|
+
}
|
|
62
|
+
declare abstract class Isolator {
|
|
63
|
+
abstract execute(options: ExecuteOptions): Promise<ExecuteResult>;
|
|
64
|
+
abstract getFileSystem(): FileSystem;
|
|
65
|
+
abstract destroy(): Promise<void>;
|
|
66
|
+
}
|
|
67
|
+
declare class LocalIsolator extends Isolator {
|
|
68
|
+
private workDir;
|
|
69
|
+
private runtime;
|
|
70
|
+
constructor(runtime?: string);
|
|
71
|
+
execute(options: ExecuteOptions): Promise<ExecuteResult>;
|
|
72
|
+
/**
|
|
73
|
+
* Build command array based on runtime
|
|
74
|
+
*/
|
|
75
|
+
private buildCommand;
|
|
76
|
+
getFileSystem(): FileSystem;
|
|
77
|
+
destroy(): Promise<void>;
|
|
78
|
+
}
|
|
79
|
+
declare class CloudflareContainerIsolator extends Isolator {
|
|
80
|
+
private serverProcess?;
|
|
81
|
+
private serverUrl?;
|
|
82
|
+
private isReady;
|
|
83
|
+
private runtime;
|
|
84
|
+
constructor(runtime?: string);
|
|
85
|
+
/**
|
|
86
|
+
* Find an available port
|
|
87
|
+
*/
|
|
88
|
+
private findFreePort;
|
|
89
|
+
/**
|
|
90
|
+
* Get binary path from installed package
|
|
91
|
+
*/
|
|
92
|
+
private getBinaryPath;
|
|
93
|
+
/**
|
|
94
|
+
* Wait for server to be ready
|
|
95
|
+
*/
|
|
96
|
+
private waitForReady;
|
|
97
|
+
/**
|
|
98
|
+
* Ensure server is running
|
|
99
|
+
*/
|
|
100
|
+
private ensureServerRunning;
|
|
101
|
+
execute(options: ExecuteOptions): Promise<ExecuteResult>;
|
|
102
|
+
getFileSystem(): FileSystem;
|
|
103
|
+
destroy(): Promise<void>;
|
|
104
|
+
}
|
|
105
|
+
declare abstract class Runtime2 {
|
|
106
|
+
abstract execute(options: ExecuteOptions): Promise<ExecuteResult>;
|
|
107
|
+
abstract prepare(): Promise<void>;
|
|
108
|
+
abstract cleanup(): Promise<void>;
|
|
109
|
+
}
|
|
110
|
+
declare class GenericRuntime extends Runtime2 {
|
|
111
|
+
private isolator;
|
|
112
|
+
constructor(isolator: Isolator);
|
|
113
|
+
execute(options: ExecuteOptions): Promise<ExecuteResult>;
|
|
114
|
+
prepare(): Promise<void>;
|
|
115
|
+
cleanup(): Promise<void>;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Error types for SandboX
|
|
119
|
+
*/
|
|
120
|
+
declare class SandboxError extends Error {
|
|
121
|
+
constructor(message: string);
|
|
122
|
+
}
|
|
123
|
+
declare class ExecutionError extends SandboxError {
|
|
124
|
+
constructor(message: string);
|
|
125
|
+
}
|
|
126
|
+
declare class TimeoutError extends SandboxError {
|
|
127
|
+
constructor(message: string);
|
|
128
|
+
}
|
|
129
|
+
declare class IsolationError extends SandboxError {
|
|
130
|
+
constructor(message: string);
|
|
131
|
+
}
|
|
132
|
+
declare class FileSystemError extends SandboxError {
|
|
133
|
+
constructor(message: string);
|
|
134
|
+
}
|
|
135
|
+
export { TimeoutError, SandboxError, SandboxConfig, Sandbox, Runtime2 as Runtime, ResourceLimits, LocalIsolator, IsolatorType, Isolator, IsolationError, IsolationConfig, GenericRuntime, FileSystemError, FileSystem, ExecutionError, ExecuteResult, ExecuteOptions, EventHandler, CloudflareContainerIsolator };
|