@larkup/sandbox 0.1.1
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/.turbo/turbo-build.log +6 -0
- package/CHANGELOG.md +7 -0
- package/Dockerfile +30 -0
- package/LICENSE +176 -0
- package/dist/docker-runner.d.ts +12 -0
- package/dist/docker-runner.js +438 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +7 -0
- package/dist/sandbox-manager.d.ts +18 -0
- package/dist/sandbox-manager.js +97 -0
- package/dist/types.d.ts +71 -0
- package/dist/types.js +7 -0
- package/package.json +43 -0
- package/src/docker-runner.ts +483 -0
- package/src/index.ts +26 -0
- package/src/sandbox-manager.ts +124 -0
- package/src/types.ts +101 -0
- package/tsconfig.json +15 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
export type SandboxBackend = "docker" | "e2b" | "modal" | "custom";
|
|
2
|
+
|
|
3
|
+
export interface DockerConfig {
|
|
4
|
+
/** Docker image to use (default: "larkup-sandbox:latest") */
|
|
5
|
+
imageName: string;
|
|
6
|
+
/** Memory limit in MB (default: 512) */
|
|
7
|
+
memoryMB: number;
|
|
8
|
+
/** CPU shares (default: 1024 = 1 core) */
|
|
9
|
+
cpuShares: number;
|
|
10
|
+
/** Max execution time in ms (default: 30000) */
|
|
11
|
+
timeoutMs: number;
|
|
12
|
+
/** Disable network access in the container (default: true) */
|
|
13
|
+
networkDisabled: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface RemoteConfig {
|
|
17
|
+
provider: "e2b" | "modal" | "custom";
|
|
18
|
+
apiKey: string;
|
|
19
|
+
endpoint?: string;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface SandboxConfig {
|
|
23
|
+
backend: SandboxBackend;
|
|
24
|
+
docker?: Partial<DockerConfig>;
|
|
25
|
+
remote?: RemoteConfig;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const DEFAULT_DOCKER_CONFIG: DockerConfig = {
|
|
29
|
+
imageName: "larkup-sandbox:latest",
|
|
30
|
+
memoryMB: 512,
|
|
31
|
+
cpuShares: 1024,
|
|
32
|
+
timeoutMs: 30_000,
|
|
33
|
+
networkDisabled: true,
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/* ------------------------------------------------------------------ */
|
|
37
|
+
/* Execution request / result */
|
|
38
|
+
/* ------------------------------------------------------------------ */
|
|
39
|
+
|
|
40
|
+
export type SandboxLanguage = "python" | "javascript" | "typescript";
|
|
41
|
+
|
|
42
|
+
export interface SandboxFile {
|
|
43
|
+
/** Filename inside the sandbox (e.g., "data.csv") */
|
|
44
|
+
name: string;
|
|
45
|
+
/** File content as a string (text) or base64 (binary) */
|
|
46
|
+
content: string;
|
|
47
|
+
/** Whether content is base64-encoded (default: false) */
|
|
48
|
+
isBase64?: boolean;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface ExecutionRequest {
|
|
52
|
+
/** Code to execute */
|
|
53
|
+
code: string;
|
|
54
|
+
/** Programming language */
|
|
55
|
+
language: SandboxLanguage;
|
|
56
|
+
/** Files to mount into the sandbox working directory */
|
|
57
|
+
files?: SandboxFile[];
|
|
58
|
+
/** Max execution time in ms (overrides config default) */
|
|
59
|
+
timeout?: number;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface ExecutionArtifact {
|
|
63
|
+
/** Filename of the generated artifact */
|
|
64
|
+
name: string;
|
|
65
|
+
/** MIME type (e.g., "image/png", "text/csv") */
|
|
66
|
+
mimeType: string;
|
|
67
|
+
/** Content as base64-encoded string */
|
|
68
|
+
data: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface ExecutionResult {
|
|
72
|
+
/** Standard output from the execution */
|
|
73
|
+
stdout: string;
|
|
74
|
+
/** Standard error output */
|
|
75
|
+
stderr: string;
|
|
76
|
+
/** Process exit code (0 = success) */
|
|
77
|
+
exitCode: number;
|
|
78
|
+
/** Generated files (charts, CSVs, etc.) */
|
|
79
|
+
artifacts: ExecutionArtifact[];
|
|
80
|
+
/** Wall-clock execution time in ms */
|
|
81
|
+
executionTimeMs: number;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/* ------------------------------------------------------------------ */
|
|
85
|
+
/* Sandbox status */
|
|
86
|
+
/* ------------------------------------------------------------------ */
|
|
87
|
+
|
|
88
|
+
export type SandboxStatus =
|
|
89
|
+
| "ready"
|
|
90
|
+
| "docker-not-found"
|
|
91
|
+
| "image-not-found"
|
|
92
|
+
| "building-image"
|
|
93
|
+
| "error";
|
|
94
|
+
|
|
95
|
+
export interface SandboxHealthCheck {
|
|
96
|
+
status: SandboxStatus;
|
|
97
|
+
backend: SandboxBackend;
|
|
98
|
+
dockerVersion?: string;
|
|
99
|
+
imageReady?: boolean;
|
|
100
|
+
error?: string;
|
|
101
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "NodeNext",
|
|
5
|
+
"moduleResolution": "NodeNext",
|
|
6
|
+
"esModuleInterop": true,
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"strict": true,
|
|
9
|
+
"skipLibCheck": true,
|
|
10
|
+
"outDir": "dist",
|
|
11
|
+
"rootDir": "src"
|
|
12
|
+
},
|
|
13
|
+
"include": ["src"],
|
|
14
|
+
"exclude": ["node_modules", "dist"]
|
|
15
|
+
}
|