@axiom-lattice/microsandbox-service 0.0.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 +29 -0
- package/CHANGELOG.md +7 -0
- package/LICENSE +201 -0
- package/dist/chunk-2W4CTYPX.mjs +464 -0
- package/dist/chunk-2W4CTYPX.mjs.map +1 -0
- package/dist/index.d.mts +208 -0
- package/dist/index.d.ts +208 -0
- package/dist/index.js +496 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +11 -0
- package/dist/index.mjs.map +1 -0
- package/dist/server.d.mts +9 -0
- package/dist/server.d.ts +9 -0
- package/dist/server.js +566 -0
- package/dist/server.js.map +1 -0
- package/dist/server.mjs +82 -0
- package/dist/server.mjs.map +1 -0
- package/jest.config.js +17 -0
- package/package.json +46 -0
- package/src/__tests__/MicrosandboxRuntimeService.test.ts +251 -0
- package/src/__tests__/SandboxRegistry.test.ts +101 -0
- package/src/__tests__/app.test.ts +224 -0
- package/src/__tests__/index.test.ts +33 -0
- package/src/__tests__/server-cli.test.ts +26 -0
- package/src/__tests__/server.test.ts +25 -0
- package/src/app.ts +31 -0
- package/src/controllers/sandbox.ts +138 -0
- package/src/index.ts +3 -0
- package/src/lib/errors.ts +44 -0
- package/src/lib/http.ts +11 -0
- package/src/lib/server-cli.ts +59 -0
- package/src/routes/health.ts +6 -0
- package/src/routes/sandbox.ts +28 -0
- package/src/schemas/sandbox.ts +79 -0
- package/src/server.ts +43 -0
- package/src/services/MicrosandboxRuntimeService.ts +247 -0
- package/src/services/SandboxRegistry.ts +69 -0
- package/src/types/runtime-service.ts +23 -0
- package/tsconfig.json +22 -0
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { FastifyInstance } from 'fastify';
|
|
2
|
+
import z from 'zod';
|
|
3
|
+
|
|
4
|
+
declare const ensureSandboxSchema: z.ZodObject<{
|
|
5
|
+
image: z.ZodOptional<z.ZodString>;
|
|
6
|
+
cpus: z.ZodOptional<z.ZodNumber>;
|
|
7
|
+
memoryMib: z.ZodOptional<z.ZodNumber>;
|
|
8
|
+
env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
9
|
+
volumes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodObject<{
|
|
10
|
+
type: z.ZodLiteral<"bind">;
|
|
11
|
+
source: z.ZodString;
|
|
12
|
+
readonly: z.ZodOptional<z.ZodBoolean>;
|
|
13
|
+
}, "strip", z.ZodTypeAny, {
|
|
14
|
+
type: "bind";
|
|
15
|
+
source: string;
|
|
16
|
+
readonly?: boolean | undefined;
|
|
17
|
+
}, {
|
|
18
|
+
type: "bind";
|
|
19
|
+
source: string;
|
|
20
|
+
readonly?: boolean | undefined;
|
|
21
|
+
}>, z.ZodObject<{
|
|
22
|
+
type: z.ZodLiteral<"named">;
|
|
23
|
+
name: z.ZodString;
|
|
24
|
+
readonly: z.ZodOptional<z.ZodBoolean>;
|
|
25
|
+
}, "strip", z.ZodTypeAny, {
|
|
26
|
+
type: "named";
|
|
27
|
+
name: string;
|
|
28
|
+
readonly?: boolean | undefined;
|
|
29
|
+
}, {
|
|
30
|
+
type: "named";
|
|
31
|
+
name: string;
|
|
32
|
+
readonly?: boolean | undefined;
|
|
33
|
+
}>, z.ZodObject<{
|
|
34
|
+
type: z.ZodLiteral<"tmpfs">;
|
|
35
|
+
sizeMib: z.ZodOptional<z.ZodNumber>;
|
|
36
|
+
}, "strip", z.ZodTypeAny, {
|
|
37
|
+
type: "tmpfs";
|
|
38
|
+
sizeMib?: number | undefined;
|
|
39
|
+
}, {
|
|
40
|
+
type: "tmpfs";
|
|
41
|
+
sizeMib?: number | undefined;
|
|
42
|
+
}>]>>>;
|
|
43
|
+
}, "strip", z.ZodTypeAny, {
|
|
44
|
+
image?: string | undefined;
|
|
45
|
+
cpus?: number | undefined;
|
|
46
|
+
memoryMib?: number | undefined;
|
|
47
|
+
env?: Record<string, string> | undefined;
|
|
48
|
+
volumes?: Record<string, {
|
|
49
|
+
type: "bind";
|
|
50
|
+
source: string;
|
|
51
|
+
readonly?: boolean | undefined;
|
|
52
|
+
} | {
|
|
53
|
+
type: "named";
|
|
54
|
+
name: string;
|
|
55
|
+
readonly?: boolean | undefined;
|
|
56
|
+
} | {
|
|
57
|
+
type: "tmpfs";
|
|
58
|
+
sizeMib?: number | undefined;
|
|
59
|
+
}> | undefined;
|
|
60
|
+
}, {
|
|
61
|
+
image?: string | undefined;
|
|
62
|
+
cpus?: number | undefined;
|
|
63
|
+
memoryMib?: number | undefined;
|
|
64
|
+
env?: Record<string, string> | undefined;
|
|
65
|
+
volumes?: Record<string, {
|
|
66
|
+
type: "bind";
|
|
67
|
+
source: string;
|
|
68
|
+
readonly?: boolean | undefined;
|
|
69
|
+
} | {
|
|
70
|
+
type: "named";
|
|
71
|
+
name: string;
|
|
72
|
+
readonly?: boolean | undefined;
|
|
73
|
+
} | {
|
|
74
|
+
type: "tmpfs";
|
|
75
|
+
sizeMib?: number | undefined;
|
|
76
|
+
}> | undefined;
|
|
77
|
+
}>;
|
|
78
|
+
declare const shellExecSchema: z.ZodObject<{
|
|
79
|
+
sandboxName: z.ZodString;
|
|
80
|
+
command: z.ZodString;
|
|
81
|
+
exec_dir: z.ZodOptional<z.ZodString>;
|
|
82
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
83
|
+
}, "strip", z.ZodTypeAny, {
|
|
84
|
+
sandboxName: string;
|
|
85
|
+
command: string;
|
|
86
|
+
exec_dir?: string | undefined;
|
|
87
|
+
timeout?: number | undefined;
|
|
88
|
+
}, {
|
|
89
|
+
sandboxName: string;
|
|
90
|
+
command: string;
|
|
91
|
+
exec_dir?: string | undefined;
|
|
92
|
+
timeout?: number | undefined;
|
|
93
|
+
}>;
|
|
94
|
+
type EnsureSandboxInput = z.infer<typeof ensureSandboxSchema>;
|
|
95
|
+
type ShellExecInput = z.infer<typeof shellExecSchema>;
|
|
96
|
+
|
|
97
|
+
interface RuntimeService {
|
|
98
|
+
ensureSandbox(name: string, input: EnsureSandboxInput): Promise<unknown>;
|
|
99
|
+
startSandbox(name: string): Promise<unknown>;
|
|
100
|
+
stopSandbox(name: string): Promise<unknown>;
|
|
101
|
+
killSandbox(name: string): Promise<unknown>;
|
|
102
|
+
deleteSandbox(name: string): Promise<unknown>;
|
|
103
|
+
getStatus(name: string): Promise<unknown>;
|
|
104
|
+
readFile(sandboxName: string, path: string): Promise<unknown>;
|
|
105
|
+
writeFile(sandboxName: string, path: string, content: string): Promise<unknown>;
|
|
106
|
+
listPath(sandboxName: string, path: string, recursive?: boolean): Promise<unknown>;
|
|
107
|
+
findFiles(sandboxName: string, path: string, pattern: string): Promise<unknown>;
|
|
108
|
+
searchInFile(sandboxName: string, path: string, query: string): Promise<unknown>;
|
|
109
|
+
replaceInFile(sandboxName: string, input: {
|
|
110
|
+
path: string;
|
|
111
|
+
search: string;
|
|
112
|
+
replace: string;
|
|
113
|
+
}): Promise<unknown>;
|
|
114
|
+
uploadFile(sandboxName: string, path: string, contentBase64: string): Promise<unknown>;
|
|
115
|
+
downloadFile(sandboxName: string, path: string): Promise<unknown>;
|
|
116
|
+
execCommand(input: ShellExecInput): Promise<unknown>;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
declare function buildApp({ runtimeService, }?: {
|
|
120
|
+
runtimeService?: RuntimeService;
|
|
121
|
+
}): FastifyInstance;
|
|
122
|
+
|
|
123
|
+
declare class SandboxRegistry {
|
|
124
|
+
private handles;
|
|
125
|
+
private creating;
|
|
126
|
+
ensure(name: string, createOptions?: Record<string, unknown>): Promise<unknown>;
|
|
127
|
+
get(name: string): unknown;
|
|
128
|
+
delete(name: string): void;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
declare class MicrosandboxRuntimeService {
|
|
132
|
+
private deps;
|
|
133
|
+
constructor(deps?: {
|
|
134
|
+
registry?: SandboxRegistry;
|
|
135
|
+
});
|
|
136
|
+
private get registry();
|
|
137
|
+
private buildVolumes;
|
|
138
|
+
private buildVolume;
|
|
139
|
+
private getNative;
|
|
140
|
+
private getOrEnsureNative;
|
|
141
|
+
ensureSandbox(name: string, input: EnsureSandboxInput): Promise<{
|
|
142
|
+
name: string;
|
|
143
|
+
status: string;
|
|
144
|
+
}>;
|
|
145
|
+
startSandbox(name: string): Promise<{
|
|
146
|
+
name: string;
|
|
147
|
+
status: string;
|
|
148
|
+
}>;
|
|
149
|
+
stopSandbox(name: string): Promise<{
|
|
150
|
+
name: string;
|
|
151
|
+
status: string;
|
|
152
|
+
}>;
|
|
153
|
+
killSandbox(name: string): Promise<{
|
|
154
|
+
name: string;
|
|
155
|
+
status: string;
|
|
156
|
+
}>;
|
|
157
|
+
deleteSandbox(name: string): Promise<{
|
|
158
|
+
name: string;
|
|
159
|
+
status: string;
|
|
160
|
+
}>;
|
|
161
|
+
getStatus(name: string): Promise<{
|
|
162
|
+
name: string;
|
|
163
|
+
status: string;
|
|
164
|
+
}>;
|
|
165
|
+
readFile(sandboxName: string, path: string): Promise<{
|
|
166
|
+
path: string;
|
|
167
|
+
content: string;
|
|
168
|
+
}>;
|
|
169
|
+
writeFile(sandboxName: string, path: string, content: string): Promise<{
|
|
170
|
+
path: string;
|
|
171
|
+
}>;
|
|
172
|
+
listPath(sandboxName: string, path: string, recursive?: boolean): Promise<{
|
|
173
|
+
entries: Array<{
|
|
174
|
+
path: string;
|
|
175
|
+
type: string;
|
|
176
|
+
}>;
|
|
177
|
+
}>;
|
|
178
|
+
findFiles(sandboxName: string, path: string, pattern: string): Promise<{
|
|
179
|
+
files: string[];
|
|
180
|
+
}>;
|
|
181
|
+
searchInFile(sandboxName: string, path: string, query: string): Promise<{
|
|
182
|
+
matches: Array<{
|
|
183
|
+
line: number;
|
|
184
|
+
content: string;
|
|
185
|
+
}>;
|
|
186
|
+
}>;
|
|
187
|
+
replaceInFile(sandboxName: string, input: {
|
|
188
|
+
path: string;
|
|
189
|
+
search: string;
|
|
190
|
+
replace: string;
|
|
191
|
+
}): Promise<{
|
|
192
|
+
replaced: number;
|
|
193
|
+
}>;
|
|
194
|
+
uploadFile(sandboxName: string, path: string, contentBase64: string): Promise<{
|
|
195
|
+
path: string;
|
|
196
|
+
}>;
|
|
197
|
+
downloadFile(sandboxName: string, path: string): Promise<{
|
|
198
|
+
path: string;
|
|
199
|
+
contentBase64: string;
|
|
200
|
+
}>;
|
|
201
|
+
execCommand(input: ShellExecInput): Promise<{
|
|
202
|
+
stdout: string;
|
|
203
|
+
stderr: string;
|
|
204
|
+
exitCode: number;
|
|
205
|
+
}>;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export { MicrosandboxRuntimeService, SandboxRegistry, buildApp };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { FastifyInstance } from 'fastify';
|
|
2
|
+
import z from 'zod';
|
|
3
|
+
|
|
4
|
+
declare const ensureSandboxSchema: z.ZodObject<{
|
|
5
|
+
image: z.ZodOptional<z.ZodString>;
|
|
6
|
+
cpus: z.ZodOptional<z.ZodNumber>;
|
|
7
|
+
memoryMib: z.ZodOptional<z.ZodNumber>;
|
|
8
|
+
env: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
9
|
+
volumes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodObject<{
|
|
10
|
+
type: z.ZodLiteral<"bind">;
|
|
11
|
+
source: z.ZodString;
|
|
12
|
+
readonly: z.ZodOptional<z.ZodBoolean>;
|
|
13
|
+
}, "strip", z.ZodTypeAny, {
|
|
14
|
+
type: "bind";
|
|
15
|
+
source: string;
|
|
16
|
+
readonly?: boolean | undefined;
|
|
17
|
+
}, {
|
|
18
|
+
type: "bind";
|
|
19
|
+
source: string;
|
|
20
|
+
readonly?: boolean | undefined;
|
|
21
|
+
}>, z.ZodObject<{
|
|
22
|
+
type: z.ZodLiteral<"named">;
|
|
23
|
+
name: z.ZodString;
|
|
24
|
+
readonly: z.ZodOptional<z.ZodBoolean>;
|
|
25
|
+
}, "strip", z.ZodTypeAny, {
|
|
26
|
+
type: "named";
|
|
27
|
+
name: string;
|
|
28
|
+
readonly?: boolean | undefined;
|
|
29
|
+
}, {
|
|
30
|
+
type: "named";
|
|
31
|
+
name: string;
|
|
32
|
+
readonly?: boolean | undefined;
|
|
33
|
+
}>, z.ZodObject<{
|
|
34
|
+
type: z.ZodLiteral<"tmpfs">;
|
|
35
|
+
sizeMib: z.ZodOptional<z.ZodNumber>;
|
|
36
|
+
}, "strip", z.ZodTypeAny, {
|
|
37
|
+
type: "tmpfs";
|
|
38
|
+
sizeMib?: number | undefined;
|
|
39
|
+
}, {
|
|
40
|
+
type: "tmpfs";
|
|
41
|
+
sizeMib?: number | undefined;
|
|
42
|
+
}>]>>>;
|
|
43
|
+
}, "strip", z.ZodTypeAny, {
|
|
44
|
+
image?: string | undefined;
|
|
45
|
+
cpus?: number | undefined;
|
|
46
|
+
memoryMib?: number | undefined;
|
|
47
|
+
env?: Record<string, string> | undefined;
|
|
48
|
+
volumes?: Record<string, {
|
|
49
|
+
type: "bind";
|
|
50
|
+
source: string;
|
|
51
|
+
readonly?: boolean | undefined;
|
|
52
|
+
} | {
|
|
53
|
+
type: "named";
|
|
54
|
+
name: string;
|
|
55
|
+
readonly?: boolean | undefined;
|
|
56
|
+
} | {
|
|
57
|
+
type: "tmpfs";
|
|
58
|
+
sizeMib?: number | undefined;
|
|
59
|
+
}> | undefined;
|
|
60
|
+
}, {
|
|
61
|
+
image?: string | undefined;
|
|
62
|
+
cpus?: number | undefined;
|
|
63
|
+
memoryMib?: number | undefined;
|
|
64
|
+
env?: Record<string, string> | undefined;
|
|
65
|
+
volumes?: Record<string, {
|
|
66
|
+
type: "bind";
|
|
67
|
+
source: string;
|
|
68
|
+
readonly?: boolean | undefined;
|
|
69
|
+
} | {
|
|
70
|
+
type: "named";
|
|
71
|
+
name: string;
|
|
72
|
+
readonly?: boolean | undefined;
|
|
73
|
+
} | {
|
|
74
|
+
type: "tmpfs";
|
|
75
|
+
sizeMib?: number | undefined;
|
|
76
|
+
}> | undefined;
|
|
77
|
+
}>;
|
|
78
|
+
declare const shellExecSchema: z.ZodObject<{
|
|
79
|
+
sandboxName: z.ZodString;
|
|
80
|
+
command: z.ZodString;
|
|
81
|
+
exec_dir: z.ZodOptional<z.ZodString>;
|
|
82
|
+
timeout: z.ZodOptional<z.ZodNumber>;
|
|
83
|
+
}, "strip", z.ZodTypeAny, {
|
|
84
|
+
sandboxName: string;
|
|
85
|
+
command: string;
|
|
86
|
+
exec_dir?: string | undefined;
|
|
87
|
+
timeout?: number | undefined;
|
|
88
|
+
}, {
|
|
89
|
+
sandboxName: string;
|
|
90
|
+
command: string;
|
|
91
|
+
exec_dir?: string | undefined;
|
|
92
|
+
timeout?: number | undefined;
|
|
93
|
+
}>;
|
|
94
|
+
type EnsureSandboxInput = z.infer<typeof ensureSandboxSchema>;
|
|
95
|
+
type ShellExecInput = z.infer<typeof shellExecSchema>;
|
|
96
|
+
|
|
97
|
+
interface RuntimeService {
|
|
98
|
+
ensureSandbox(name: string, input: EnsureSandboxInput): Promise<unknown>;
|
|
99
|
+
startSandbox(name: string): Promise<unknown>;
|
|
100
|
+
stopSandbox(name: string): Promise<unknown>;
|
|
101
|
+
killSandbox(name: string): Promise<unknown>;
|
|
102
|
+
deleteSandbox(name: string): Promise<unknown>;
|
|
103
|
+
getStatus(name: string): Promise<unknown>;
|
|
104
|
+
readFile(sandboxName: string, path: string): Promise<unknown>;
|
|
105
|
+
writeFile(sandboxName: string, path: string, content: string): Promise<unknown>;
|
|
106
|
+
listPath(sandboxName: string, path: string, recursive?: boolean): Promise<unknown>;
|
|
107
|
+
findFiles(sandboxName: string, path: string, pattern: string): Promise<unknown>;
|
|
108
|
+
searchInFile(sandboxName: string, path: string, query: string): Promise<unknown>;
|
|
109
|
+
replaceInFile(sandboxName: string, input: {
|
|
110
|
+
path: string;
|
|
111
|
+
search: string;
|
|
112
|
+
replace: string;
|
|
113
|
+
}): Promise<unknown>;
|
|
114
|
+
uploadFile(sandboxName: string, path: string, contentBase64: string): Promise<unknown>;
|
|
115
|
+
downloadFile(sandboxName: string, path: string): Promise<unknown>;
|
|
116
|
+
execCommand(input: ShellExecInput): Promise<unknown>;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
declare function buildApp({ runtimeService, }?: {
|
|
120
|
+
runtimeService?: RuntimeService;
|
|
121
|
+
}): FastifyInstance;
|
|
122
|
+
|
|
123
|
+
declare class SandboxRegistry {
|
|
124
|
+
private handles;
|
|
125
|
+
private creating;
|
|
126
|
+
ensure(name: string, createOptions?: Record<string, unknown>): Promise<unknown>;
|
|
127
|
+
get(name: string): unknown;
|
|
128
|
+
delete(name: string): void;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
declare class MicrosandboxRuntimeService {
|
|
132
|
+
private deps;
|
|
133
|
+
constructor(deps?: {
|
|
134
|
+
registry?: SandboxRegistry;
|
|
135
|
+
});
|
|
136
|
+
private get registry();
|
|
137
|
+
private buildVolumes;
|
|
138
|
+
private buildVolume;
|
|
139
|
+
private getNative;
|
|
140
|
+
private getOrEnsureNative;
|
|
141
|
+
ensureSandbox(name: string, input: EnsureSandboxInput): Promise<{
|
|
142
|
+
name: string;
|
|
143
|
+
status: string;
|
|
144
|
+
}>;
|
|
145
|
+
startSandbox(name: string): Promise<{
|
|
146
|
+
name: string;
|
|
147
|
+
status: string;
|
|
148
|
+
}>;
|
|
149
|
+
stopSandbox(name: string): Promise<{
|
|
150
|
+
name: string;
|
|
151
|
+
status: string;
|
|
152
|
+
}>;
|
|
153
|
+
killSandbox(name: string): Promise<{
|
|
154
|
+
name: string;
|
|
155
|
+
status: string;
|
|
156
|
+
}>;
|
|
157
|
+
deleteSandbox(name: string): Promise<{
|
|
158
|
+
name: string;
|
|
159
|
+
status: string;
|
|
160
|
+
}>;
|
|
161
|
+
getStatus(name: string): Promise<{
|
|
162
|
+
name: string;
|
|
163
|
+
status: string;
|
|
164
|
+
}>;
|
|
165
|
+
readFile(sandboxName: string, path: string): Promise<{
|
|
166
|
+
path: string;
|
|
167
|
+
content: string;
|
|
168
|
+
}>;
|
|
169
|
+
writeFile(sandboxName: string, path: string, content: string): Promise<{
|
|
170
|
+
path: string;
|
|
171
|
+
}>;
|
|
172
|
+
listPath(sandboxName: string, path: string, recursive?: boolean): Promise<{
|
|
173
|
+
entries: Array<{
|
|
174
|
+
path: string;
|
|
175
|
+
type: string;
|
|
176
|
+
}>;
|
|
177
|
+
}>;
|
|
178
|
+
findFiles(sandboxName: string, path: string, pattern: string): Promise<{
|
|
179
|
+
files: string[];
|
|
180
|
+
}>;
|
|
181
|
+
searchInFile(sandboxName: string, path: string, query: string): Promise<{
|
|
182
|
+
matches: Array<{
|
|
183
|
+
line: number;
|
|
184
|
+
content: string;
|
|
185
|
+
}>;
|
|
186
|
+
}>;
|
|
187
|
+
replaceInFile(sandboxName: string, input: {
|
|
188
|
+
path: string;
|
|
189
|
+
search: string;
|
|
190
|
+
replace: string;
|
|
191
|
+
}): Promise<{
|
|
192
|
+
replaced: number;
|
|
193
|
+
}>;
|
|
194
|
+
uploadFile(sandboxName: string, path: string, contentBase64: string): Promise<{
|
|
195
|
+
path: string;
|
|
196
|
+
}>;
|
|
197
|
+
downloadFile(sandboxName: string, path: string): Promise<{
|
|
198
|
+
path: string;
|
|
199
|
+
contentBase64: string;
|
|
200
|
+
}>;
|
|
201
|
+
execCommand(input: ShellExecInput): Promise<{
|
|
202
|
+
stdout: string;
|
|
203
|
+
stderr: string;
|
|
204
|
+
exitCode: number;
|
|
205
|
+
}>;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export { MicrosandboxRuntimeService, SandboxRegistry, buildApp };
|