@cloudflare/sandbox 0.0.0-7bccc85 → 0.0.0-8a93d0c
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/CHANGELOG.md +88 -0
- package/Dockerfile +72 -10
- package/README.md +520 -23
- package/container_src/handler/exec.ts +340 -0
- package/container_src/handler/file.ts +844 -0
- package/container_src/handler/git.ts +182 -0
- package/container_src/handler/ports.ts +314 -0
- package/container_src/handler/process.ts +640 -0
- package/container_src/index.ts +110 -2649
- package/container_src/types.ts +108 -0
- package/package.json +6 -8
- package/src/client.ts +351 -1242
- package/src/index.ts +20 -129
- package/src/request-handler.ts +144 -0
- package/src/sandbox.ts +650 -0
- package/src/security.ts +113 -0
- package/src/sse-parser.ts +147 -0
- package/src/types.ts +386 -0
- package/tsconfig.json +1 -1
- package/tests/client.example.ts +0 -308
- package/tests/connection-test.ts +0 -81
- package/tests/simple-test.ts +0 -81
- package/tests/test1.ts +0 -281
- package/tests/test2.ts +0 -929
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { ChildProcess } from "node:child_process";
|
|
2
|
+
|
|
3
|
+
// Process management types
|
|
4
|
+
export type ProcessStatus =
|
|
5
|
+
| 'starting'
|
|
6
|
+
| 'running'
|
|
7
|
+
| 'completed'
|
|
8
|
+
| 'failed'
|
|
9
|
+
| 'killed'
|
|
10
|
+
| 'error';
|
|
11
|
+
|
|
12
|
+
export interface ProcessRecord {
|
|
13
|
+
id: string;
|
|
14
|
+
pid?: number;
|
|
15
|
+
command: string;
|
|
16
|
+
status: ProcessStatus;
|
|
17
|
+
startTime: Date;
|
|
18
|
+
endTime?: Date;
|
|
19
|
+
exitCode?: number;
|
|
20
|
+
sessionId?: string;
|
|
21
|
+
childProcess?: ChildProcess;
|
|
22
|
+
stdout: string;
|
|
23
|
+
stderr: string;
|
|
24
|
+
outputListeners: Set<(stream: 'stdout' | 'stderr', data: string) => void>;
|
|
25
|
+
statusListeners: Set<(status: ProcessStatus) => void>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface StartProcessRequest {
|
|
29
|
+
command: string;
|
|
30
|
+
options?: {
|
|
31
|
+
processId?: string;
|
|
32
|
+
sessionId?: string;
|
|
33
|
+
timeout?: number;
|
|
34
|
+
env?: Record<string, string>;
|
|
35
|
+
cwd?: string;
|
|
36
|
+
encoding?: string;
|
|
37
|
+
autoCleanup?: boolean;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface ExecuteOptions {
|
|
42
|
+
sessionId?: string | null;
|
|
43
|
+
background?: boolean;
|
|
44
|
+
cwd?: string | URL;
|
|
45
|
+
env?: Record<string, string>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface ExecuteRequest extends ExecuteOptions {
|
|
49
|
+
command: string;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface GitCheckoutRequest {
|
|
53
|
+
repoUrl: string;
|
|
54
|
+
branch?: string;
|
|
55
|
+
targetDir?: string;
|
|
56
|
+
sessionId?: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface MkdirRequest {
|
|
60
|
+
path: string;
|
|
61
|
+
recursive?: boolean;
|
|
62
|
+
sessionId?: string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface WriteFileRequest {
|
|
66
|
+
path: string;
|
|
67
|
+
content: string;
|
|
68
|
+
encoding?: string;
|
|
69
|
+
sessionId?: string;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export interface ReadFileRequest {
|
|
73
|
+
path: string;
|
|
74
|
+
encoding?: string;
|
|
75
|
+
sessionId?: string;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export interface DeleteFileRequest {
|
|
79
|
+
path: string;
|
|
80
|
+
sessionId?: string;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export interface RenameFileRequest {
|
|
84
|
+
oldPath: string;
|
|
85
|
+
newPath: string;
|
|
86
|
+
sessionId?: string;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export interface MoveFileRequest {
|
|
90
|
+
sourcePath: string;
|
|
91
|
+
destinationPath: string;
|
|
92
|
+
sessionId?: string;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export interface ExposePortRequest {
|
|
96
|
+
port: number;
|
|
97
|
+
name?: string;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export interface UnexposePortRequest {
|
|
101
|
+
port: number;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export interface SessionData {
|
|
105
|
+
sessionId: string;
|
|
106
|
+
activeProcess: ChildProcess | null;
|
|
107
|
+
createdAt: Date;
|
|
108
|
+
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudflare/sandbox",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-8a93d0c",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/cloudflare/sandbox-sdk"
|
|
7
7
|
},
|
|
8
8
|
"description": "A sandboxed environment for running commands",
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"@cloudflare/containers": "^0.0.
|
|
10
|
+
"@cloudflare/containers": "^0.0.25"
|
|
11
11
|
},
|
|
12
12
|
"tags": [
|
|
13
13
|
"sandbox",
|
|
@@ -17,18 +17,16 @@
|
|
|
17
17
|
"durable objects"
|
|
18
18
|
],
|
|
19
19
|
"scripts": {
|
|
20
|
-
"build": "tsup src/*.ts --outDir dist --dts --sourcemap --format esm"
|
|
20
|
+
"build": "rm -rf dist && tsup src/*.ts --outDir dist --dts --sourcemap --format esm",
|
|
21
|
+
"docker:local": "docker build . -t cloudflare/sandbox-test:$npm_package_version",
|
|
22
|
+
"docker:publish": "docker buildx build --platform linux/amd64,linux/arm64 -t cloudflare/sandbox:$npm_package_version --push .",
|
|
23
|
+
"docker:publish:beta": "docker buildx build --platform linux/amd64,linux/arm64 -t cloudflare/sandbox:$npm_package_version-beta --push ."
|
|
21
24
|
},
|
|
22
25
|
"exports": {
|
|
23
26
|
".": {
|
|
24
27
|
"types": "./dist/index.d.ts",
|
|
25
28
|
"import": "./dist/index.js",
|
|
26
29
|
"require": "./dist/index.js"
|
|
27
|
-
},
|
|
28
|
-
"./client": {
|
|
29
|
-
"types": "./dist/client.d.ts",
|
|
30
|
-
"import": "./dist/client.js",
|
|
31
|
-
"require": "./dist/client.js"
|
|
32
30
|
}
|
|
33
31
|
},
|
|
34
32
|
"keywords": [],
|