@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
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Sandbox protocol — WebSocket message types between sandbox-client and service.
3
+ *
4
+ * This protocol covers lifecycle steps 3-5:
5
+ * Register: client sends RegisterMessage, service responds RegisteredMessage
6
+ * Ready: heartbeat keeps connection alive
7
+ * Command: service sends commands, client returns results
8
+ *
9
+ * All sandbox-clients (cloud, web, future types) speak this same protocol.
10
+ *
11
+ * Lifecycle: Allocate → Prepare → Register → Ready → Command
12
+ * ^^^^^^^^^^^^^^^^^^^^^^^^^^^
13
+ */
14
+ export interface RegisterMessage {
15
+ type: "register";
16
+ sandboxId: string;
17
+ token: string;
18
+ }
19
+ export interface ResultMessage {
20
+ type: "result";
21
+ id: string;
22
+ stdout: string;
23
+ stderr: string;
24
+ exitCode: number;
25
+ }
26
+ export interface FsResultMessage {
27
+ type: "fs.result";
28
+ id: string;
29
+ data: unknown;
30
+ }
31
+ export interface ErrorMessage {
32
+ type: "error";
33
+ id: string;
34
+ message: string;
35
+ }
36
+ export interface HeartbeatMessage {
37
+ type: "heartbeat";
38
+ }
39
+ export interface ExecMessage {
40
+ type: "exec";
41
+ id: string;
42
+ command: string;
43
+ cwd?: string;
44
+ timeout?: number;
45
+ }
46
+ export interface FsReadMessage {
47
+ type: "fs.read";
48
+ id: string;
49
+ path: string;
50
+ }
51
+ export interface FsWriteMessage {
52
+ type: "fs.write";
53
+ id: string;
54
+ path: string;
55
+ content: string;
56
+ }
57
+ export interface FsListMessage {
58
+ type: "fs.list";
59
+ id: string;
60
+ path: string;
61
+ }
62
+ export interface FsMkdirMessage {
63
+ type: "fs.mkdir";
64
+ id: string;
65
+ path: string;
66
+ recursive?: boolean;
67
+ }
68
+ export interface FsDeleteMessage {
69
+ type: "fs.delete";
70
+ id: string;
71
+ path: string;
72
+ }
73
+ export interface ProcessStartMessage {
74
+ type: "process.start";
75
+ id: string;
76
+ command: string;
77
+ cwd?: string;
78
+ }
79
+ export interface ProcessKillMessage {
80
+ type: "process.kill";
81
+ id: string;
82
+ processId: string;
83
+ }
84
+ export interface ProcessListMessage {
85
+ type: "process.list";
86
+ id: string;
87
+ }
88
+ export interface RegisteredMessage {
89
+ type: "registered";
90
+ sandboxId: string;
91
+ }
92
+ /** Messages sent from sandbox-client to service */
93
+ export type ClientMessage = RegisterMessage | ResultMessage | FsResultMessage | ErrorMessage | HeartbeatMessage;
94
+ /** Messages sent from service to sandbox-client */
95
+ export type ServiceMessage = ExecMessage | FsReadMessage | FsWriteMessage | FsListMessage | FsMkdirMessage | FsDeleteMessage | ProcessStartMessage | ProcessKillMessage | ProcessListMessage | RegisteredMessage;
96
+ //# sourceMappingURL=protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,UAAU,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,QAAQ,CAAC;IACf,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,WAAW,CAAC;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,OAAO,CAAC;IACd,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,WAAW,CAAC;CACnB;AAID,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,SAAS,CAAC;IAChB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,UAAU,CAAC;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,SAAS,CAAC;IAChB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,UAAU,CAAC;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,WAAW,CAAC;IAClB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,eAAe,CAAC;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,cAAc,CAAC;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,cAAc,CAAC;IACrB,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,YAAY,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;CACnB;AAID,mDAAmD;AACnD,MAAM,MAAM,aAAa,GACrB,eAAe,GACf,aAAa,GACb,eAAe,GACf,YAAY,GACZ,gBAAgB,CAAC;AAErB,mDAAmD;AACnD,MAAM,MAAM,cAAc,GACtB,WAAW,GACX,aAAa,GACb,cAAc,GACd,aAAa,GACb,cAAc,GACd,eAAe,GACf,mBAAmB,GACnB,kBAAkB,GAClB,kBAAkB,GAClB,iBAAiB,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Sandbox protocol — WebSocket message types between sandbox-client and service.
3
+ *
4
+ * This protocol covers lifecycle steps 3-5:
5
+ * Register: client sends RegisterMessage, service responds RegisteredMessage
6
+ * Ready: heartbeat keeps connection alive
7
+ * Command: service sends commands, client returns results
8
+ *
9
+ * All sandbox-clients (cloud, web, future types) speak this same protocol.
10
+ *
11
+ * Lifecycle: Allocate → Prepare → Register → Ready → Command
12
+ * ^^^^^^^^^^^^^^^^^^^^^^^^^^^
13
+ */
14
+ export {};
15
+ //# sourceMappingURL=protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * SandboxProvider — platform capability injection.
3
+ *
4
+ * Provider is a component factory that supplies platform-specific
5
+ * implementations of Executor, FileSystem, and ProcessManager.
6
+ *
7
+ * The core layer (createSandboxClient) only depends on this interface.
8
+ * Platform differences are isolated in provider implementations:
9
+ * - node-provider: child_process + node:fs
10
+ * - web-provider: @webcontainer/api
11
+ * - Future: Docker, SSH, etc.
12
+ */
13
+ import type { ExecOptions, ExecResult, FileInfo, ProcessInfo } from "./sandbox";
14
+ /**
15
+ * Command execution component.
16
+ */
17
+ export interface SandboxExecutor {
18
+ exec(command: string, options?: ExecOptions): Promise<ExecResult>;
19
+ }
20
+ /**
21
+ * File system component.
22
+ */
23
+ export interface SandboxFileSystem {
24
+ readFile(path: string): Promise<string>;
25
+ writeFile(path: string, content: string): Promise<void>;
26
+ listFiles(path: string): Promise<FileInfo[]>;
27
+ mkdir(path: string, options?: {
28
+ recursive?: boolean;
29
+ }): Promise<void>;
30
+ deleteFile(path: string): Promise<void>;
31
+ }
32
+ /**
33
+ * Process management component.
34
+ */
35
+ export interface SandboxProcessManager {
36
+ start(command: string, options?: {
37
+ cwd?: string;
38
+ }): Promise<ProcessInfo>;
39
+ kill(processId: string): Promise<void>;
40
+ list(): Promise<ProcessInfo[]>;
41
+ }
42
+ /**
43
+ * SandboxProvider — the component factory.
44
+ *
45
+ * Each platform implements this interface to provide its components.
46
+ * createSandboxClient(provider) obtains components and dispatches
47
+ * incoming messages to the appropriate component.
48
+ */
49
+ export interface SandboxProvider {
50
+ createExecutor(): SandboxExecutor;
51
+ createFileSystem(): SandboxFileSystem;
52
+ createProcessManager(): SandboxProcessManager;
53
+ }
54
+ //# sourceMappingURL=provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAEhF;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;CACnE;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACxC,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACxD,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC7C,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtE,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACzC;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IACzE,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACvC,IAAI,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;CAChC;AAED;;;;;;GAMG;AACH,MAAM,WAAW,eAAe;IAC9B,cAAc,IAAI,eAAe,CAAC;IAClC,gBAAgB,IAAI,iBAAiB,CAAC;IACtC,oBAAoB,IAAI,qBAAqB,CAAC;CAC/C"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * SandboxProvider — platform capability injection.
3
+ *
4
+ * Provider is a component factory that supplies platform-specific
5
+ * implementations of Executor, FileSystem, and ProcessManager.
6
+ *
7
+ * The core layer (createSandboxClient) only depends on this interface.
8
+ * Platform differences are isolated in provider implementations:
9
+ * - node-provider: child_process + node:fs
10
+ * - web-provider: @webcontainer/api
11
+ * - Future: Docker, SSH, etc.
12
+ */
13
+ export {};
14
+ //# sourceMappingURL=provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * SandboxRegistry — accepts sandbox-client connections and manages lifecycle.
3
+ *
4
+ * Step 3-4 of the lifecycle: Register → Ready.
5
+ *
6
+ * When a sandbox-client connects via WebSocket and sends a register message,
7
+ * the registry:
8
+ * 1. Validates the token
9
+ * 2. Binds the WebSocket connection to the sandboxId
10
+ * 3. Updates the sandbox status from "pending" to "ready"
11
+ * 4. Provides the command routing channel
12
+ *
13
+ * The registry also handles disconnection, heartbeat, and reconnection.
14
+ *
15
+ * Lifecycle: Allocate → Prepare → Register → Ready → Command
16
+ * ^^^^^^^^^^^^^^^^^
17
+ */
18
+ export interface SandboxConnection {
19
+ sandboxId: string;
20
+ connectedAt: number;
21
+ }
22
+ export interface SandboxRegistry {
23
+ /** Check if a sandbox-client is connected and ready */
24
+ has(sandboxId: string): boolean;
25
+ /** List all active connections */
26
+ connections(): SandboxConnection[];
27
+ }
28
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,MAAM,WAAW,iBAAiB;IAChC,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,eAAe;IAC9B,uDAAuD;IACvD,GAAG,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC;IAChC,kCAAkC;IAClC,WAAW,IAAI,iBAAiB,EAAE,CAAC;CACpC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * SandboxRegistry — accepts sandbox-client connections and manages lifecycle.
3
+ *
4
+ * Step 3-4 of the lifecycle: Register → Ready.
5
+ *
6
+ * When a sandbox-client connects via WebSocket and sends a register message,
7
+ * the registry:
8
+ * 1. Validates the token
9
+ * 2. Binds the WebSocket connection to the sandboxId
10
+ * 3. Updates the sandbox status from "pending" to "ready"
11
+ * 4. Provides the command routing channel
12
+ *
13
+ * The registry also handles disconnection, heartbeat, and reconnection.
14
+ *
15
+ * Lifecycle: Allocate → Prepare → Register → Ready → Command
16
+ * ^^^^^^^^^^^^^^^^^
17
+ */
18
+ export {};
19
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * SandboxRouter — routes RPC methods to sandbox operations.
3
+ *
4
+ * Step 5 of the lifecycle: Command.
5
+ *
6
+ * The router is the external-facing RPC interface.
7
+ * It combines the allocator (lifecycle) and registry (connections)
8
+ * to provide a unified dispatch: method + params → result.
9
+ *
10
+ * Internally, it resolves the sandboxId from params, finds the
11
+ * connected sandbox-client through the registry, and forwards
12
+ * the command over WebSocket.
13
+ *
14
+ * Lifecycle: Allocate → Prepare → Register → Ready → Command
15
+ * ^^^^^^^
16
+ */
17
+ import type { Sandbox } from "./sandbox";
18
+ export interface SandboxRouter {
19
+ /** Get a Sandbox handle by id — routes through registry to connected client */
20
+ getSandbox(sandboxId: string): Sandbox;
21
+ /** Dispatch an RPC method with params */
22
+ dispatch(method: string, params: Record<string, unknown>): Promise<unknown>;
23
+ }
24
+ //# sourceMappingURL=router.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEzC,MAAM,WAAW,aAAa;IAC5B,+EAA+E;IAC/E,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC;IACvC,yCAAyC;IACzC,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC7E"}
package/dist/router.js ADDED
@@ -0,0 +1,18 @@
1
+ /**
2
+ * SandboxRouter — routes RPC methods to sandbox operations.
3
+ *
4
+ * Step 5 of the lifecycle: Command.
5
+ *
6
+ * The router is the external-facing RPC interface.
7
+ * It combines the allocator (lifecycle) and registry (connections)
8
+ * to provide a unified dispatch: method + params → result.
9
+ *
10
+ * Internally, it resolves the sandboxId from params, finds the
11
+ * connected sandbox-client through the registry, and forwards
12
+ * the command over WebSocket.
13
+ *
14
+ * Lifecycle: Allocate → Prepare → Register → Ready → Command
15
+ * ^^^^^^^
16
+ */
17
+ export {};
18
+ //# sourceMappingURL=router.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"router.js","sourceRoot":"","sources":["../src/router.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Sandbox — the unified interface for sandbox operations.
3
+ *
4
+ * Step 5 of the lifecycle: Command.
5
+ *
6
+ * Consumers get a Sandbox instance and operate on it.
7
+ * They never need to know if it's a cloud container, a browser WebContainer,
8
+ * or any other sandbox type. All commands are routed through the registry
9
+ * to the connected sandbox-client.
10
+ *
11
+ * Lifecycle: Allocate → Prepare → Register → Ready → Command
12
+ * ^^^^^^^
13
+ */
14
+ export interface ExecOptions {
15
+ cwd?: string;
16
+ timeout?: number;
17
+ }
18
+ export interface ExecResult {
19
+ stdout: string;
20
+ stderr: string;
21
+ exitCode: number;
22
+ success: boolean;
23
+ }
24
+ export interface ProcessInfo {
25
+ id: string;
26
+ pid?: number;
27
+ command: string;
28
+ status: string;
29
+ }
30
+ export interface FileInfo {
31
+ name: string;
32
+ type: "file" | "directory" | "symlink";
33
+ size?: number;
34
+ }
35
+ export interface Sandbox {
36
+ exec(command: string, options?: ExecOptions): Promise<ExecResult>;
37
+ startProcess(command: string, options?: {
38
+ cwd?: string;
39
+ }): Promise<ProcessInfo>;
40
+ killProcess(processId: string): Promise<void>;
41
+ listProcesses(): Promise<ProcessInfo[]>;
42
+ readFile(path: string): Promise<string>;
43
+ writeFile(path: string, content: string): Promise<void>;
44
+ listFiles(path: string): Promise<FileInfo[]>;
45
+ mkdir(path: string, options?: {
46
+ recursive?: boolean;
47
+ }): Promise<void>;
48
+ deleteFile(path: string): Promise<void>;
49
+ exposePort(port: number, hostname: string): Promise<{
50
+ url: string;
51
+ }>;
52
+ destroy(): Promise<void>;
53
+ }
54
+ //# sourceMappingURL=sandbox.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sandbox.d.ts","sourceRoot":"","sources":["../src/sandbox.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,MAAM,WAAW,WAAW;IAC1B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CAAC;IACvC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,OAAO;IACtB,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IAClE,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IAChF,WAAW,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9C,aAAa,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC,CAAC;IACxC,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACxC,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACxD,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC7C,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtE,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACxC,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACrE,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1B"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Sandbox — the unified interface for sandbox operations.
3
+ *
4
+ * Step 5 of the lifecycle: Command.
5
+ *
6
+ * Consumers get a Sandbox instance and operate on it.
7
+ * They never need to know if it's a cloud container, a browser WebContainer,
8
+ * or any other sandbox type. All commands are routed through the registry
9
+ * to the connected sandbox-client.
10
+ *
11
+ * Lifecycle: Allocate → Prepare → Register → Ready → Command
12
+ * ^^^^^^^
13
+ */
14
+ export {};
15
+ //# sourceMappingURL=sandbox.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sandbox.js","sourceRoot":"","sources":["../src/sandbox.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG"}
package/package.json CHANGED
@@ -1,51 +1,26 @@
1
1
  {
2
2
  "name": "@sandboxxjs/core",
3
- "version": "0.5.0",
4
- "description": "SandboX Core - Secure code execution engine",
5
- "keywords": [
6
- "sandbox",
7
- "execution",
8
- "security",
9
- "isolation"
10
- ],
11
- "repository": {
12
- "type": "git",
13
- "url": "git+https://github.com/Deepractice/SandboX.git",
14
- "directory": "packages/core"
15
- },
16
- "license": "MIT",
17
- "engines": {
18
- "node": ">=22.0.0"
19
- },
3
+ "version": "2.0.0",
4
+ "description": "Core interfaces and runtime for sandboxxjs — unified sandbox lifecycle",
20
5
  "type": "module",
21
- "main": "./dist/index.js",
22
- "types": "./dist/index.d.ts",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
23
8
  "exports": {
24
9
  ".": {
25
10
  "types": "./dist/index.d.ts",
26
- "default": "./dist/index.js"
11
+ "import": "./dist/index.js"
12
+ },
13
+ "./protocol": {
14
+ "types": "./dist/protocol.d.ts",
15
+ "import": "./dist/protocol.js"
27
16
  }
28
17
  },
29
- "files": [
30
- "dist",
31
- "README.md"
32
- ],
33
18
  "scripts": {
34
- "build": "bun run build.ts",
35
- "lint": "eslint .",
19
+ "build": "tsc",
36
20
  "typecheck": "tsc --noEmit",
37
- "test": "bun test",
38
21
  "clean": "rm -rf dist"
39
22
  },
40
- "devDependencies": {},
41
23
  "publishConfig": {
42
24
  "access": "public"
43
- },
44
- "dependencies": {
45
- "@anthropic-ai/sandbox-runtime": "^0.0.32",
46
- "@sandboxxjs/cloudflare-isolator": "^0.5.0",
47
- "@sandboxxjs/state": "^0.5.0",
48
- "execa": "^9.6.1",
49
- "nanoid": "^5.1.6"
50
25
  }
51
26
  }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * SandboxAllocator — provisions sandbox resources.
3
+ *
4
+ * Step 1 of the lifecycle: Allocate.
5
+ *
6
+ * The allocator creates a sandbox environment and returns a SandboxContainer
7
+ * with status "pending". The sandbox is NOT ready for commands yet —
8
+ * it becomes ready only after a sandbox-client connects and registers.
9
+ *
10
+ * Lifecycle: Allocate → Prepare → Register → Ready → Command
11
+ * ^^^^^^^^
12
+ */
13
+
14
+ export type SandboxContainerType = "cloud" | "web";
15
+
16
+ export type SandboxStatus = "pending" | "ready" | "destroyed";
17
+
18
+ export interface SandboxContainer {
19
+ id: string;
20
+ type: SandboxContainerType;
21
+ status: SandboxStatus;
22
+ createdAt: number;
23
+ source?: string;
24
+ /** Connection info for sandbox-client to register */
25
+ connection: {
26
+ wsUrl: string;
27
+ token: string;
28
+ };
29
+ }
30
+
31
+ export interface AllocateRequest {
32
+ type?: SandboxContainerType;
33
+ sandboxId?: string;
34
+ source?: string;
35
+ }
36
+
37
+ export interface SandboxAllocator {
38
+ /** Allocate a sandbox — returns container with status "pending" */
39
+ allocate(request: AllocateRequest): Promise<SandboxContainer>;
40
+ /** Release sandbox resources */
41
+ deallocate(sandboxId: string): Promise<void>;
42
+ /** List all sandboxes */
43
+ list(): Promise<SandboxContainer[]>;
44
+ /** Get a single sandbox by id */
45
+ get(sandboxId: string): Promise<SandboxContainer | null>;
46
+ /** Update sandbox status (called by registry on registration) */
47
+ updateStatus(sandboxId: string, status: SandboxStatus): Promise<void>;
48
+ }
package/src/client.ts ADDED
@@ -0,0 +1,51 @@
1
+ /**
2
+ * SandboxClient — the agent that runs inside every sandbox environment.
3
+ *
4
+ * Step 2-3 of the lifecycle: Prepare → Register.
5
+ *
6
+ * After allocation, the sandbox environment starts a SandboxClient.
7
+ * The client connects to the service via WebSocket, registers itself,
8
+ * and then listens for commands (exec, fs, process operations).
9
+ *
10
+ * The client is platform-agnostic. Platform differences are injected
11
+ * via SandboxProvider, which supplies Executor, FileSystem, and
12
+ * ProcessManager components:
13
+ * - node-provider: child_process + node:fs
14
+ * - web-provider: @webcontainer/api
15
+ * - Future: Docker, SSH, etc.
16
+ *
17
+ * Lifecycle: Allocate → Prepare → Register → Ready → Command
18
+ * ^^^^^^^^^^^^^^^^^
19
+ */
20
+
21
+ /**
22
+ * Connection options for a sandbox-client.
23
+ */
24
+ export interface SandboxClientOptions {
25
+ /** WebSocket URL of the sandbox service registry */
26
+ wsUrl: string;
27
+ /** Sandbox identifier */
28
+ sandboxId: string;
29
+ /** Authentication token */
30
+ token: string;
31
+ /** Heartbeat interval in milliseconds (default: 30000) */
32
+ heartbeatInterval?: number;
33
+ }
34
+
35
+ /**
36
+ * SandboxClient — connects to service, receives commands, executes via provider components.
37
+ *
38
+ * Usage:
39
+ * const provider = new NodeProvider(); // or WebContainerProvider
40
+ * const client = createSandboxClient(provider);
41
+ * await client.connect({ wsUrl, sandboxId, token });
42
+ * // Client is now registered and listening for commands
43
+ */
44
+ export interface SandboxClient {
45
+ /** Connect to the sandbox service and register */
46
+ connect(options: SandboxClientOptions): Promise<void>;
47
+ /** Disconnect from the service */
48
+ disconnect(): Promise<void>;
49
+ /** Whether the client is connected and registered */
50
+ readonly connected: boolean;
51
+ }