@geminixiang/mama 0.2.0-beta.0 → 0.2.0-beta.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/README.md +59 -19
- package/dist/adapter.d.ts +9 -7
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js.map +1 -1
- package/dist/adapters/discord/bot.d.ts +2 -2
- package/dist/adapters/discord/bot.d.ts.map +1 -1
- package/dist/adapters/discord/bot.js +33 -21
- package/dist/adapters/discord/bot.js.map +1 -1
- package/dist/adapters/discord/context.d.ts.map +1 -1
- package/dist/adapters/discord/context.js +20 -13
- package/dist/adapters/discord/context.js.map +1 -1
- package/dist/adapters/slack/bot.d.ts +4 -3
- package/dist/adapters/slack/bot.d.ts.map +1 -1
- package/dist/adapters/slack/bot.js +68 -30
- package/dist/adapters/slack/bot.js.map +1 -1
- package/dist/adapters/slack/context.d.ts.map +1 -1
- package/dist/adapters/slack/context.js +22 -12
- package/dist/adapters/slack/context.js.map +1 -1
- package/dist/adapters/telegram/bot.d.ts +2 -2
- package/dist/adapters/telegram/bot.d.ts.map +1 -1
- package/dist/adapters/telegram/bot.js +54 -33
- package/dist/adapters/telegram/bot.js.map +1 -1
- package/dist/adapters/telegram/context.d.ts.map +1 -1
- package/dist/adapters/telegram/context.js +61 -10
- package/dist/adapters/telegram/context.js.map +1 -1
- package/dist/agent.d.ts +7 -4
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js +152 -96
- package/dist/agent.js.map +1 -1
- package/dist/bindings.d.ts +63 -0
- package/dist/bindings.d.ts.map +1 -0
- package/dist/bindings.js +94 -0
- package/dist/bindings.js.map +1 -0
- package/dist/config.d.ts +32 -5
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +71 -44
- package/dist/config.js.map +1 -1
- package/dist/context.d.ts +6 -6
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +8 -8
- package/dist/context.js.map +1 -1
- package/dist/events.d.ts +4 -0
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +20 -5
- package/dist/events.js.map +1 -1
- package/dist/execution-resolver.d.ts +20 -0
- package/dist/execution-resolver.d.ts.map +1 -0
- package/dist/execution-resolver.js +51 -0
- package/dist/execution-resolver.js.map +1 -0
- package/dist/instrument.d.ts.map +1 -1
- package/dist/instrument.js +11 -4
- package/dist/instrument.js.map +1 -1
- package/dist/link-server.d.ts +16 -0
- package/dist/link-server.d.ts.map +1 -0
- package/dist/link-server.js +839 -0
- package/dist/link-server.js.map +1 -0
- package/dist/link-token.d.ts +32 -0
- package/dist/link-token.d.ts.map +1 -0
- package/dist/link-token.js +68 -0
- package/dist/link-token.js.map +1 -0
- package/dist/log.d.ts +2 -2
- package/dist/log.d.ts.map +1 -1
- package/dist/log.js +7 -7
- package/dist/log.js.map +1 -1
- package/dist/login.d.ts +29 -0
- package/dist/login.d.ts.map +1 -0
- package/dist/login.js +164 -0
- package/dist/login.js.map +1 -0
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +243 -56
- package/dist/main.js.map +1 -1
- package/dist/provisioner.d.ts +93 -0
- package/dist/provisioner.d.ts.map +1 -0
- package/dist/provisioner.js +336 -0
- package/dist/provisioner.js.map +1 -0
- package/dist/sandbox/container.d.ts +15 -0
- package/dist/sandbox/container.d.ts.map +1 -0
- package/dist/sandbox/container.js +122 -0
- package/dist/sandbox/container.js.map +1 -0
- package/dist/sandbox/errors.d.ts +6 -0
- package/dist/sandbox/errors.d.ts.map +1 -0
- package/dist/sandbox/errors.js +11 -0
- package/dist/sandbox/errors.js.map +1 -0
- package/dist/sandbox/firecracker.d.ts +16 -0
- package/dist/sandbox/firecracker.d.ts.map +1 -0
- package/dist/sandbox/firecracker.js +206 -0
- package/dist/sandbox/firecracker.js.map +1 -0
- package/dist/sandbox/host.d.ts +12 -0
- package/dist/sandbox/host.d.ts.map +1 -0
- package/dist/sandbox/host.js +89 -0
- package/dist/sandbox/host.js.map +1 -0
- package/dist/sandbox/image.d.ts +5 -0
- package/dist/sandbox/image.d.ts.map +1 -0
- package/dist/sandbox/image.js +30 -0
- package/dist/sandbox/image.js.map +1 -0
- package/dist/sandbox/index.d.ts +20 -0
- package/dist/sandbox/index.d.ts.map +1 -0
- package/dist/sandbox/index.js +51 -0
- package/dist/sandbox/index.js.map +1 -0
- package/dist/sandbox/types.d.ts +51 -0
- package/dist/sandbox/types.d.ts.map +1 -0
- package/dist/sandbox/types.js +2 -0
- package/dist/sandbox/types.js.map +1 -0
- package/dist/sandbox/utils.d.ts +4 -0
- package/dist/sandbox/utils.d.ts.map +1 -0
- package/dist/sandbox/utils.js +51 -0
- package/dist/sandbox/utils.js.map +1 -0
- package/dist/sandbox.d.ts +1 -39
- package/dist/sandbox.d.ts.map +1 -1
- package/dist/sandbox.js +1 -286
- package/dist/sandbox.js.map +1 -1
- package/dist/sentry.d.ts +1 -1
- package/dist/sentry.d.ts.map +1 -1
- package/dist/sentry.js +2 -2
- package/dist/sentry.js.map +1 -1
- package/dist/session-store.d.ts +1 -5
- package/dist/session-store.d.ts.map +1 -1
- package/dist/session-store.js +7 -10
- package/dist/session-store.js.map +1 -1
- package/dist/store.d.ts +1 -1
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +8 -8
- package/dist/store.js.map +1 -1
- package/dist/tools/event.d.ts +21 -0
- package/dist/tools/event.d.ts.map +1 -0
- package/dist/tools/event.js +103 -0
- package/dist/tools/event.js.map +1 -0
- package/dist/tools/index.d.ts +6 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +5 -1
- package/dist/tools/index.js.map +1 -1
- package/dist/ui-copy.d.ts +11 -0
- package/dist/ui-copy.d.ts.map +1 -0
- package/dist/ui-copy.js +33 -0
- package/dist/ui-copy.js.map +1 -0
- package/dist/vault-routing.d.ts +10 -0
- package/dist/vault-routing.d.ts.map +1 -0
- package/dist/vault-routing.js +58 -0
- package/dist/vault-routing.js.map +1 -0
- package/dist/vault.d.ts +106 -0
- package/dist/vault.d.ts.map +1 -0
- package/dist/vault.js +389 -0
- package/dist/vault.js.map +1 -0
- package/dist/vault.test.d.ts +2 -0
- package/dist/vault.test.d.ts.map +1 -0
- package/dist/vault.test.js +67 -0
- package/dist/vault.test.js.map +1 -0
- package/package.json +12 -11
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { spawn } from "child_process";
|
|
2
|
+
import { SandboxError } from "./errors.js";
|
|
3
|
+
import { HostExecutor } from "./host.js";
|
|
4
|
+
import { execSimple, killProcessTree, shellEscape } from "./utils.js";
|
|
5
|
+
export function parseFirecrackerSandboxArg(value) {
|
|
6
|
+
if (!value.startsWith("firecracker:")) {
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
const arg = value.slice("firecracker:".length);
|
|
10
|
+
// Format: firecracker:<vm-id>:<host-path>[:<ssh-user>[:<ssh-port>]]
|
|
11
|
+
// Example: firecracker:vm1:/home/user/workspace
|
|
12
|
+
// firecracker:vm1:/home/user/workspace:root
|
|
13
|
+
// firecracker:vm1:/home/user/workspace:root:22
|
|
14
|
+
const parts = arg.split(":");
|
|
15
|
+
if (parts.length < 2) {
|
|
16
|
+
throw new SandboxError("Error: firecracker sandbox requires vm-id and host-path\n" +
|
|
17
|
+
"Usage: firecracker:<vm-id>:<host-path>[:<ssh-user>[:<ssh-port>]]\n" +
|
|
18
|
+
"Example: firecracker:vm1:/home/user/workspace");
|
|
19
|
+
}
|
|
20
|
+
const vmId = parts[0];
|
|
21
|
+
const hostPath = parts[1];
|
|
22
|
+
const sshUser = parts[2] || "root";
|
|
23
|
+
const sshPort = parts[3] ? parseInt(parts[3], 10) : 22;
|
|
24
|
+
if (!vmId || !hostPath) {
|
|
25
|
+
throw new SandboxError("Error: firecracker sandbox requires vm-id and host-path");
|
|
26
|
+
}
|
|
27
|
+
if (isNaN(sshPort) || sshPort <= 0 || sshPort > 65535) {
|
|
28
|
+
throw new SandboxError("Error: invalid SSH port");
|
|
29
|
+
}
|
|
30
|
+
return { type: "firecracker", vmId, hostPath, sshUser, sshPort };
|
|
31
|
+
}
|
|
32
|
+
export async function validateFirecrackerSandbox(config) {
|
|
33
|
+
// Check if fc-agent or firecracker CLI is available
|
|
34
|
+
try {
|
|
35
|
+
await execSimple("fc-agent", ["--version"]);
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
// Try alternative: firecracker
|
|
39
|
+
try {
|
|
40
|
+
await execSimple("firecracker", ["--version"]);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
throw new SandboxError("Error: Firecracker tools (fc-agent or firecracker) not found in PATH", ["Install firecracker: https://github.com/firecracker-microvm/firecracker"]);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// Check if VM is running using fc-agent
|
|
47
|
+
try {
|
|
48
|
+
const result = await execSimple("fc-agent", ["status", config.vmId]);
|
|
49
|
+
if (!result.includes("running") && !result.includes("Running")) {
|
|
50
|
+
throw new SandboxError(`Error: Firecracker VM '${config.vmId}' is not running.`, [
|
|
51
|
+
`Start it with: fc-agent start ${config.vmId}`,
|
|
52
|
+
]);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
if (error instanceof SandboxError) {
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
// Try alternative: firecracker-ctl or direct check
|
|
60
|
+
try {
|
|
61
|
+
await execSimple("firecracker-ctl", ["status", config.vmId]);
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
console.error(`Warning: Could not verify if VM '${config.vmId}' is running.`);
|
|
65
|
+
console.error("Make sure the VM is started before running mama.");
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// Verify host path exists
|
|
69
|
+
try {
|
|
70
|
+
await execSimple("ls", ["-d", config.hostPath]);
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
throw new SandboxError(`Error: Host path '${config.hostPath}' does not exist.`);
|
|
74
|
+
}
|
|
75
|
+
console.log(` Firecracker VM '${config.vmId}' configured with workspace '${config.hostPath}'.`);
|
|
76
|
+
}
|
|
77
|
+
export class FirecrackerExecutor {
|
|
78
|
+
constructor(vmId, hostPath, sshUser = "root", sshPort = 22, env) {
|
|
79
|
+
this.vmId = vmId;
|
|
80
|
+
this.hostPath = hostPath;
|
|
81
|
+
this.sshUser = sshUser;
|
|
82
|
+
this.sshPort = sshPort;
|
|
83
|
+
this.env = env;
|
|
84
|
+
}
|
|
85
|
+
async exec(command, options) {
|
|
86
|
+
if (!this.env || Object.keys(this.env).length === 0) {
|
|
87
|
+
const sshCmd = this.sshPort === 22
|
|
88
|
+
? `ssh -o StrictHostKeyChecking=no -o ConnectTimeout=10 ${this.sshUser}@${this.vmId} sh -c ${shellEscape(command)}`
|
|
89
|
+
: `ssh -o StrictHostKeyChecking=no -o ConnectTimeout=10 -p ${this.sshPort} ${this.sshUser}@${this.vmId} sh -c ${shellEscape(command)}`;
|
|
90
|
+
const hostExecutor = new HostExecutor();
|
|
91
|
+
return hostExecutor.exec(sshCmd, options);
|
|
92
|
+
}
|
|
93
|
+
return new Promise((resolve, reject) => {
|
|
94
|
+
const sshArgs = ["-o", "StrictHostKeyChecking=no", "-o", "ConnectTimeout=10"];
|
|
95
|
+
if (this.sshPort !== 22) {
|
|
96
|
+
sshArgs.push("-p", String(this.sshPort));
|
|
97
|
+
}
|
|
98
|
+
sshArgs.push(`${this.sshUser}@${this.vmId}`, "sh", "-se");
|
|
99
|
+
const child = spawn("ssh", sshArgs, {
|
|
100
|
+
detached: true,
|
|
101
|
+
stdio: ["pipe", "pipe", "pipe"],
|
|
102
|
+
});
|
|
103
|
+
let stdout = "";
|
|
104
|
+
let stderr = "";
|
|
105
|
+
let timedOut = false;
|
|
106
|
+
let settled = false;
|
|
107
|
+
const timeoutHandle = options?.timeout && options.timeout > 0
|
|
108
|
+
? setTimeout(() => {
|
|
109
|
+
timedOut = true;
|
|
110
|
+
if (child.pid)
|
|
111
|
+
killProcessTree(child.pid);
|
|
112
|
+
}, options.timeout * 1000)
|
|
113
|
+
: undefined;
|
|
114
|
+
const onAbort = () => {
|
|
115
|
+
if (child.pid)
|
|
116
|
+
killProcessTree(child.pid);
|
|
117
|
+
};
|
|
118
|
+
if (options?.signal) {
|
|
119
|
+
if (options.signal.aborted) {
|
|
120
|
+
onAbort();
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
options.signal.addEventListener("abort", onAbort, { once: true });
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
child.on("error", (error) => {
|
|
127
|
+
if (settled)
|
|
128
|
+
return;
|
|
129
|
+
settled = true;
|
|
130
|
+
if (timeoutHandle)
|
|
131
|
+
clearTimeout(timeoutHandle);
|
|
132
|
+
if (options?.signal) {
|
|
133
|
+
options.signal.removeEventListener("abort", onAbort);
|
|
134
|
+
}
|
|
135
|
+
reject(error);
|
|
136
|
+
});
|
|
137
|
+
child.stdout?.on("data", (data) => {
|
|
138
|
+
stdout += data.toString();
|
|
139
|
+
if (stdout.length > 10 * 1024 * 1024) {
|
|
140
|
+
stdout = stdout.slice(0, 10 * 1024 * 1024);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
child.stderr?.on("data", (data) => {
|
|
144
|
+
stderr += data.toString();
|
|
145
|
+
if (stderr.length > 10 * 1024 * 1024) {
|
|
146
|
+
stderr = stderr.slice(0, 10 * 1024 * 1024);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
child.stdin?.on("error", (error) => {
|
|
150
|
+
stderr += `${error.message}\n`;
|
|
151
|
+
});
|
|
152
|
+
child.stdin?.end(buildRemoteScript(command, this.env));
|
|
153
|
+
child.on("close", (code) => {
|
|
154
|
+
if (settled)
|
|
155
|
+
return;
|
|
156
|
+
settled = true;
|
|
157
|
+
if (timeoutHandle)
|
|
158
|
+
clearTimeout(timeoutHandle);
|
|
159
|
+
if (options?.signal) {
|
|
160
|
+
options.signal.removeEventListener("abort", onAbort);
|
|
161
|
+
}
|
|
162
|
+
if (options?.signal?.aborted) {
|
|
163
|
+
reject(new Error(`${stdout}\n${stderr}\nCommand aborted`.trim()));
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
if (timedOut) {
|
|
167
|
+
reject(new Error(`${stdout}\n${stderr}\nCommand timed out after ${options?.timeout} seconds`.trim()));
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
resolve({ stdout, stderr, code: code ?? 0 });
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
getWorkspacePath(_hostPath) {
|
|
175
|
+
return "/workspace";
|
|
176
|
+
}
|
|
177
|
+
getSandboxConfig() {
|
|
178
|
+
return {
|
|
179
|
+
type: "firecracker",
|
|
180
|
+
vmId: this.vmId,
|
|
181
|
+
hostPath: this.hostPath,
|
|
182
|
+
sshUser: this.sshUser,
|
|
183
|
+
sshPort: this.sshPort,
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
function buildRemoteScript(command, env) {
|
|
188
|
+
const exports = env
|
|
189
|
+
? Object.entries(env)
|
|
190
|
+
.map(([key, value]) => {
|
|
191
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key)) {
|
|
192
|
+
throw new SandboxError(`Invalid environment variable name for firecracker: ${key}`);
|
|
193
|
+
}
|
|
194
|
+
return `export ${key}=${shellEscape(value)}`;
|
|
195
|
+
})
|
|
196
|
+
.join("\n") + "\n"
|
|
197
|
+
: "";
|
|
198
|
+
return `${exports}${command}\n`;
|
|
199
|
+
}
|
|
200
|
+
export const firecrackerSandboxAdapter = {
|
|
201
|
+
type: "firecracker",
|
|
202
|
+
parse: parseFirecrackerSandboxArg,
|
|
203
|
+
validate: validateFirecrackerSandbox,
|
|
204
|
+
createExecutor: (config, env) => new FirecrackerExecutor(config.vmId, config.hostPath, config.sshUser, config.sshPort, env),
|
|
205
|
+
};
|
|
206
|
+
//# sourceMappingURL=firecracker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"firec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EAAE,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC;CAC7F,CAAC","sourcesContent":["import { spawn } from \"child_process\";\nimport type {\n ExecOptions,\n ExecResult,\n Executor,\n FirecrackerSandboxConfig,\n SandboxAdapter,\n} from \"./types.js\";\nimport { SandboxError } from \"./errors.js\";\nimport { HostExecutor } from \"./host.js\";\nimport { execSimple, killProcessTree, shellEscape } from \"./utils.js\";\n\nexport function parseFirecrackerSandboxArg(value: string): FirecrackerSandboxConfig | undefined {\n if (!value.startsWith(\"firecracker:\")) {\n return undefined;\n }\n\n const arg = value.slice(\"firecracker:\".length);\n // Format: firecracker:<vm-id>:<host-path>[:<ssh-user>[:<ssh-port>]]\n // Example: firecracker:vm1:/home/user/workspace\n // firecracker:vm1:/home/user/workspace:root\n // firecracker:vm1:/home/user/workspace:root:22\n const parts = arg.split(\":\");\n if (parts.length < 2) {\n throw new SandboxError(\n \"Error: firecracker sandbox requires vm-id and host-path\\n\" +\n \"Usage: firecracker:<vm-id>:<host-path>[:<ssh-user>[:<ssh-port>]]\\n\" +\n \"Example: firecracker:vm1:/home/user/workspace\",\n );\n }\n const vmId = parts[0];\n const hostPath = parts[1];\n const sshUser = parts[2] || \"root\";\n const sshPort = parts[3] ? parseInt(parts[3], 10) : 22;\n\n if (!vmId || !hostPath) {\n throw new SandboxError(\"Error: firecracker sandbox requires vm-id and host-path\");\n }\n if (isNaN(sshPort) || sshPort <= 0 || sshPort > 65535) {\n throw new SandboxError(\"Error: invalid SSH port\");\n }\n return { type: \"firecracker\", vmId, hostPath, sshUser, sshPort };\n}\n\nexport async function validateFirecrackerSandbox(config: FirecrackerSandboxConfig): Promise<void> {\n // Check if fc-agent or firecracker CLI is available\n try {\n await execSimple(\"fc-agent\", [\"--version\"]);\n } catch {\n // Try alternative: firecracker\n try {\n await execSimple(\"firecracker\", [\"--version\"]);\n } catch {\n throw new SandboxError(\n \"Error: Firecracker tools (fc-agent or firecracker) not found in PATH\",\n [\"Install firecracker: https://github.com/firecracker-microvm/firecracker\"],\n );\n }\n }\n\n // Check if VM is running using fc-agent\n try {\n const result = await execSimple(\"fc-agent\", [\"status\", config.vmId]);\n if (!result.includes(\"running\") && !result.includes(\"Running\")) {\n throw new SandboxError(`Error: Firecracker VM '${config.vmId}' is not running.`, [\n `Start it with: fc-agent start ${config.vmId}`,\n ]);\n }\n } catch (error) {\n if (error instanceof SandboxError) {\n throw error;\n }\n // Try alternative: firecracker-ctl or direct check\n try {\n await execSimple(\"firecracker-ctl\", [\"status\", config.vmId]);\n } catch {\n console.error(`Warning: Could not verify if VM '${config.vmId}' is running.`);\n console.error(\"Make sure the VM is started before running mama.\");\n }\n }\n\n // Verify host path exists\n try {\n await execSimple(\"ls\", [\"-d\", config.hostPath]);\n } catch {\n throw new SandboxError(`Error: Host path '${config.hostPath}' does not exist.`);\n }\n\n console.log(` Firecracker VM '${config.vmId}' configured with workspace '${config.hostPath}'.`);\n}\n\nexport class FirecrackerExecutor implements Executor {\n constructor(\n private vmId: string,\n private hostPath: string,\n private sshUser: string = \"root\",\n private sshPort: number = 22,\n private env?: Record<string, string>,\n ) {}\n\n async exec(command: string, options?: ExecOptions): Promise<ExecResult> {\n if (!this.env || Object.keys(this.env).length === 0) {\n const sshCmd =\n this.sshPort === 22\n ? `ssh -o StrictHostKeyChecking=no -o ConnectTimeout=10 ${this.sshUser}@${this.vmId} sh -c ${shellEscape(command)}`\n : `ssh -o StrictHostKeyChecking=no -o ConnectTimeout=10 -p ${this.sshPort} ${this.sshUser}@${this.vmId} sh -c ${shellEscape(command)}`;\n const hostExecutor = new HostExecutor();\n return hostExecutor.exec(sshCmd, options);\n }\n\n return new Promise((resolve, reject) => {\n const sshArgs = [\"-o\", \"StrictHostKeyChecking=no\", \"-o\", \"ConnectTimeout=10\"];\n if (this.sshPort !== 22) {\n sshArgs.push(\"-p\", String(this.sshPort));\n }\n sshArgs.push(`${this.sshUser}@${this.vmId}`, \"sh\", \"-se\");\n\n const child = spawn(\"ssh\", sshArgs, {\n detached: true,\n stdio: [\"pipe\", \"pipe\", \"pipe\"],\n });\n\n let stdout = \"\";\n let stderr = \"\";\n let timedOut = false;\n let settled = false;\n\n const timeoutHandle =\n options?.timeout && options.timeout > 0\n ? setTimeout(() => {\n timedOut = true;\n if (child.pid) killProcessTree(child.pid);\n }, options.timeout * 1000)\n : undefined;\n\n const onAbort = () => {\n if (child.pid) killProcessTree(child.pid);\n };\n\n if (options?.signal) {\n if (options.signal.aborted) {\n onAbort();\n } else {\n options.signal.addEventListener(\"abort\", onAbort, { once: true });\n }\n }\n\n child.on(\"error\", (error) => {\n if (settled) return;\n settled = true;\n if (timeoutHandle) clearTimeout(timeoutHandle);\n if (options?.signal) {\n options.signal.removeEventListener(\"abort\", onAbort);\n }\n reject(error);\n });\n\n child.stdout?.on(\"data\", (data) => {\n stdout += data.toString();\n if (stdout.length > 10 * 1024 * 1024) {\n stdout = stdout.slice(0, 10 * 1024 * 1024);\n }\n });\n\n child.stderr?.on(\"data\", (data) => {\n stderr += data.toString();\n if (stderr.length > 10 * 1024 * 1024) {\n stderr = stderr.slice(0, 10 * 1024 * 1024);\n }\n });\n\n child.stdin?.on(\"error\", (error) => {\n stderr += `${error.message}\\n`;\n });\n child.stdin?.end(buildRemoteScript(command, this.env));\n\n child.on(\"close\", (code) => {\n if (settled) return;\n settled = true;\n if (timeoutHandle) clearTimeout(timeoutHandle);\n if (options?.signal) {\n options.signal.removeEventListener(\"abort\", onAbort);\n }\n\n if (options?.signal?.aborted) {\n reject(new Error(`${stdout}\\n${stderr}\\nCommand aborted`.trim()));\n return;\n }\n\n if (timedOut) {\n reject(\n new Error(\n `${stdout}\\n${stderr}\\nCommand timed out after ${options?.timeout} seconds`.trim(),\n ),\n );\n return;\n }\n\n resolve({ stdout, stderr, code: code ?? 0 });\n });\n });\n }\n\n getWorkspacePath(_hostPath: string): string {\n return \"/workspace\";\n }\n\n getSandboxConfig(): FirecrackerSandboxConfig {\n return {\n type: \"firecracker\",\n vmId: this.vmId,\n hostPath: this.hostPath,\n sshUser: this.sshUser,\n sshPort: this.sshPort,\n };\n }\n}\n\nfunction buildRemoteScript(command: string, env?: Record<string, string>): string {\n const exports = env\n ? Object.entries(env)\n .map(([key, value]) => {\n if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key)) {\n throw new SandboxError(`Invalid environment variable name for firecracker: ${key}`);\n }\n return `export ${key}=${shellEscape(value)}`;\n })\n .join(\"\\n\") + \"\\n\"\n : \"\";\n return `${exports}${command}\\n`;\n}\n\nexport const firecrackerSandboxAdapter: SandboxAdapter<FirecrackerSandboxConfig> = {\n type: \"firecracker\",\n parse: parseFirecrackerSandboxArg,\n validate: validateFirecrackerSandbox,\n createExecutor: (config, env) =>\n new FirecrackerExecutor(config.vmId, config.hostPath, config.sshUser, config.sshPort, env),\n};\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ExecOptions, ExecResult, Executor, HostSandboxConfig, SandboxAdapter } from "./types.js";
|
|
2
|
+
export declare function parseHostSandboxArg(value: string): HostSandboxConfig | undefined;
|
|
3
|
+
export declare function validateHostSandbox(_config: HostSandboxConfig): Promise<void>;
|
|
4
|
+
export declare class HostExecutor implements Executor {
|
|
5
|
+
private env?;
|
|
6
|
+
constructor(env?: Record<string, string> | undefined);
|
|
7
|
+
exec(command: string, options?: ExecOptions): Promise<ExecResult>;
|
|
8
|
+
getWorkspacePath(hostPath: string): string;
|
|
9
|
+
getSandboxConfig(): HostSandboxConfig;
|
|
10
|
+
}
|
|
11
|
+
export declare const hostSandboxAdapter: SandboxAdapter<HostSandboxConfig>;
|
|
12
|
+
//# sourceMappingURL=host.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host.d.ts","sourceRoot":"","sources":["../../src/sandbox/host.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,WAAW,EACX,UAAU,EACV,QAAQ,EACR,iBAAiB,EACjB,cAAc,EACf,MAAM,YAAY,CAAC;AAGpB,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,iBAAiB,GAAG,SAAS,CAKhF;AAED,wBAAsB,mBAAmB,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAEnF;AAED,qBAAa,YAAa,YAAW,QAAQ;IAC/B,OAAO,CAAC,GAAG,CAAC;IAAxB,YAAoB,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,YAAA,EAAI;IAE9C,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CAwEtE;IAED,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAEzC;IAED,gBAAgB,IAAI,iBAAiB,CAEpC;CACF;AAED,eAAO,MAAM,kBAAkB,EAAE,cAAc,CAAC,iBAAiB,CAKhE,CAAC","sourcesContent":["import { spawn } from \"child_process\";\nimport type {\n ExecOptions,\n ExecResult,\n Executor,\n HostSandboxConfig,\n SandboxAdapter,\n} from \"./types.js\";\nimport { killProcessTree } from \"./utils.js\";\n\nexport function parseHostSandboxArg(value: string): HostSandboxConfig | undefined {\n if (value === \"host\") {\n return { type: \"host\" };\n }\n return undefined;\n}\n\nexport async function validateHostSandbox(_config: HostSandboxConfig): Promise<void> {\n return;\n}\n\nexport class HostExecutor implements Executor {\n constructor(private env?: Record<string, string>) {}\n\n async exec(command: string, options?: ExecOptions): Promise<ExecResult> {\n return new Promise((resolve, reject) => {\n const shell = process.platform === \"win32\" ? \"cmd\" : \"sh\";\n const shellArgs = process.platform === \"win32\" ? [\"/c\"] : [\"-c\"];\n\n const child = spawn(shell, [...shellArgs, command], {\n detached: true,\n stdio: [\"ignore\", \"pipe\", \"pipe\"],\n ...(this.env && { env: { ...process.env, ...this.env } }),\n });\n\n let stdout = \"\";\n let stderr = \"\";\n let timedOut = false;\n\n const timeoutHandle =\n options?.timeout && options.timeout > 0\n ? setTimeout(() => {\n timedOut = true;\n killProcessTree(child.pid!);\n }, options.timeout * 1000)\n : undefined;\n\n const onAbort = () => {\n if (child.pid) killProcessTree(child.pid);\n };\n\n if (options?.signal) {\n if (options.signal.aborted) {\n onAbort();\n } else {\n options.signal.addEventListener(\"abort\", onAbort, { once: true });\n }\n }\n\n child.stdout?.on(\"data\", (data) => {\n stdout += data.toString();\n if (stdout.length > 10 * 1024 * 1024) {\n stdout = stdout.slice(0, 10 * 1024 * 1024);\n }\n });\n\n child.stderr?.on(\"data\", (data) => {\n stderr += data.toString();\n if (stderr.length > 10 * 1024 * 1024) {\n stderr = stderr.slice(0, 10 * 1024 * 1024);\n }\n });\n\n child.on(\"close\", (code) => {\n if (timeoutHandle) clearTimeout(timeoutHandle);\n if (options?.signal) {\n options.signal.removeEventListener(\"abort\", onAbort);\n }\n\n if (options?.signal?.aborted) {\n reject(new Error(`${stdout}\\n${stderr}\\nCommand aborted`.trim()));\n return;\n }\n\n if (timedOut) {\n reject(\n new Error(\n `${stdout}\\n${stderr}\\nCommand timed out after ${options?.timeout} seconds`.trim(),\n ),\n );\n return;\n }\n\n resolve({ stdout, stderr, code: code ?? 0 });\n });\n });\n }\n\n getWorkspacePath(hostPath: string): string {\n return hostPath;\n }\n\n getSandboxConfig(): HostSandboxConfig {\n return { type: \"host\" };\n }\n}\n\nexport const hostSandboxAdapter: SandboxAdapter<HostSandboxConfig> = {\n type: \"host\",\n parse: parseHostSandboxArg,\n validate: validateHostSandbox,\n createExecutor: (_config, env) => new HostExecutor(env),\n};\n"]}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { spawn } from "child_process";
|
|
2
|
+
import { killProcessTree } from "./utils.js";
|
|
3
|
+
export function parseHostSandboxArg(value) {
|
|
4
|
+
if (value === "host") {
|
|
5
|
+
return { type: "host" };
|
|
6
|
+
}
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
export async function validateHostSandbox(_config) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
export class HostExecutor {
|
|
13
|
+
constructor(env) {
|
|
14
|
+
this.env = env;
|
|
15
|
+
}
|
|
16
|
+
async exec(command, options) {
|
|
17
|
+
return new Promise((resolve, reject) => {
|
|
18
|
+
const shell = process.platform === "win32" ? "cmd" : "sh";
|
|
19
|
+
const shellArgs = process.platform === "win32" ? ["/c"] : ["-c"];
|
|
20
|
+
const child = spawn(shell, [...shellArgs, command], {
|
|
21
|
+
detached: true,
|
|
22
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
23
|
+
...(this.env && { env: { ...process.env, ...this.env } }),
|
|
24
|
+
});
|
|
25
|
+
let stdout = "";
|
|
26
|
+
let stderr = "";
|
|
27
|
+
let timedOut = false;
|
|
28
|
+
const timeoutHandle = options?.timeout && options.timeout > 0
|
|
29
|
+
? setTimeout(() => {
|
|
30
|
+
timedOut = true;
|
|
31
|
+
killProcessTree(child.pid);
|
|
32
|
+
}, options.timeout * 1000)
|
|
33
|
+
: undefined;
|
|
34
|
+
const onAbort = () => {
|
|
35
|
+
if (child.pid)
|
|
36
|
+
killProcessTree(child.pid);
|
|
37
|
+
};
|
|
38
|
+
if (options?.signal) {
|
|
39
|
+
if (options.signal.aborted) {
|
|
40
|
+
onAbort();
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
options.signal.addEventListener("abort", onAbort, { once: true });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
child.stdout?.on("data", (data) => {
|
|
47
|
+
stdout += data.toString();
|
|
48
|
+
if (stdout.length > 10 * 1024 * 1024) {
|
|
49
|
+
stdout = stdout.slice(0, 10 * 1024 * 1024);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
child.stderr?.on("data", (data) => {
|
|
53
|
+
stderr += data.toString();
|
|
54
|
+
if (stderr.length > 10 * 1024 * 1024) {
|
|
55
|
+
stderr = stderr.slice(0, 10 * 1024 * 1024);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
child.on("close", (code) => {
|
|
59
|
+
if (timeoutHandle)
|
|
60
|
+
clearTimeout(timeoutHandle);
|
|
61
|
+
if (options?.signal) {
|
|
62
|
+
options.signal.removeEventListener("abort", onAbort);
|
|
63
|
+
}
|
|
64
|
+
if (options?.signal?.aborted) {
|
|
65
|
+
reject(new Error(`${stdout}\n${stderr}\nCommand aborted`.trim()));
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
if (timedOut) {
|
|
69
|
+
reject(new Error(`${stdout}\n${stderr}\nCommand timed out after ${options?.timeout} seconds`.trim()));
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
resolve({ stdout, stderr, code: code ?? 0 });
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
getWorkspacePath(hostPath) {
|
|
77
|
+
return hostPath;
|
|
78
|
+
}
|
|
79
|
+
getSandboxConfig() {
|
|
80
|
+
return { type: "host" };
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
export const hostSandboxAdapter = {
|
|
84
|
+
type: "host",
|
|
85
|
+
parse: parseHostSandboxArg,
|
|
86
|
+
validate: validateHostSandbox,
|
|
87
|
+
createExecutor: (_config, env) => new HostExecutor(env),
|
|
88
|
+
};
|
|
89
|
+
//# sourceMappingURL=host.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host.js","sourceRoot":"","sources":["../../src/sandbox/host.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAQtC,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE7C,MAAM,UAAU,mBAAmB,CAAC,KAAa;IAC/C,IAAI,KAAK,KAAK,MAAM,EAAE,CAAC;QACrB,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IAC1B,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,OAA0B;IAClE,OAAO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pB,OAAO,CAAC,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;gBACvD,CAAC;gBAED,IAAI,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;oBAC7B,MAAM,CAAC,IAAI,KAAK,CAAC,GAAG,MAAM,KAAK,MAAM,mBAAmB,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;oBAClE,OAAO;gBACT,CAAC;gBAED,IAAI,QAAQ,EAAE,CAAC;oBACb,MAAM,CACJ,IAAI,KAAK,CACP,GAAG,MAAM,KAAK,MAAM,6BAA6B,OAAO,EAAE,OAAO,UAAU,CAAC,IAAI,EAAE,CACnF,CACF,CAAC;oBACF,OAAO;gBACT,CAAC;gBAED,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,IAAI,CAAC,EAAE,CAAC,CAAC;YAC/C,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IAED,gBAAgB,CAAC,QAAgB;QAC/B,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,gBAAgB;QACd,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IAC1B,CAAC;CACF;AAED,MAAM,CAAC,MAAM,kBAAkB,GAAsC;IACnE,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,mBAAmB;IAC1B,QAAQ,EAAE,mBAAmB;IAC7B,cAAc,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,EAAE,CAAC,IAAI,YAAY,CAAC,GAAG,CAAC;CACxD,CAAC","sourcesContent":["import { spawn } from \"child_process\";\nimport type {\n ExecOptions,\n ExecResult,\n Executor,\n HostSandboxConfig,\n SandboxAdapter,\n} from \"./types.js\";\nimport { killProcessTree } from \"./utils.js\";\n\nexport function parseHostSandboxArg(value: string): HostSandboxConfig | undefined {\n if (value === \"host\") {\n return { type: \"host\" };\n }\n return undefined;\n}\n\nexport async function validateHostSandbox(_config: HostSandboxConfig): Promise<void> {\n return;\n}\n\nexport class HostExecutor implements Executor {\n constructor(private env?: Record<string, string>) {}\n\n async exec(command: string, options?: ExecOptions): Promise<ExecResult> {\n return new Promise((resolve, reject) => {\n const shell = process.platform === \"win32\" ? \"cmd\" : \"sh\";\n const shellArgs = process.platform === \"win32\" ? [\"/c\"] : [\"-c\"];\n\n const child = spawn(shell, [...shellArgs, command], {\n detached: true,\n stdio: [\"ignore\", \"pipe\", \"pipe\"],\n ...(this.env && { env: { ...process.env, ...this.env } }),\n });\n\n let stdout = \"\";\n let stderr = \"\";\n let timedOut = false;\n\n const timeoutHandle =\n options?.timeout && options.timeout > 0\n ? setTimeout(() => {\n timedOut = true;\n killProcessTree(child.pid!);\n }, options.timeout * 1000)\n : undefined;\n\n const onAbort = () => {\n if (child.pid) killProcessTree(child.pid);\n };\n\n if (options?.signal) {\n if (options.signal.aborted) {\n onAbort();\n } else {\n options.signal.addEventListener(\"abort\", onAbort, { once: true });\n }\n }\n\n child.stdout?.on(\"data\", (data) => {\n stdout += data.toString();\n if (stdout.length > 10 * 1024 * 1024) {\n stdout = stdout.slice(0, 10 * 1024 * 1024);\n }\n });\n\n child.stderr?.on(\"data\", (data) => {\n stderr += data.toString();\n if (stderr.length > 10 * 1024 * 1024) {\n stderr = stderr.slice(0, 10 * 1024 * 1024);\n }\n });\n\n child.on(\"close\", (code) => {\n if (timeoutHandle) clearTimeout(timeoutHandle);\n if (options?.signal) {\n options.signal.removeEventListener(\"abort\", onAbort);\n }\n\n if (options?.signal?.aborted) {\n reject(new Error(`${stdout}\\n${stderr}\\nCommand aborted`.trim()));\n return;\n }\n\n if (timedOut) {\n reject(\n new Error(\n `${stdout}\\n${stderr}\\nCommand timed out after ${options?.timeout} seconds`.trim(),\n ),\n );\n return;\n }\n\n resolve({ stdout, stderr, code: code ?? 0 });\n });\n });\n }\n\n getWorkspacePath(hostPath: string): string {\n return hostPath;\n }\n\n getSandboxConfig(): HostSandboxConfig {\n return { type: \"host\" };\n }\n}\n\nexport const hostSandboxAdapter: SandboxAdapter<HostSandboxConfig> = {\n type: \"host\",\n parse: parseHostSandboxArg,\n validate: validateHostSandbox,\n createExecutor: (_config, env) => new HostExecutor(env),\n};\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ImageSandboxConfig, SandboxAdapter } from "./types.js";
|
|
2
|
+
export declare function parseImageSandboxArg(value: string): ImageSandboxConfig | undefined;
|
|
3
|
+
export declare function validateImageSandbox(config: ImageSandboxConfig): Promise<void>;
|
|
4
|
+
export declare const imageSandboxAdapter: SandboxAdapter<ImageSandboxConfig>;
|
|
5
|
+
//# sourceMappingURL=image.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image.d.ts","sourceRoot":"","sources":["../../src/sandbox/image.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAIrE,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,kBAAkB,GAAG,SAAS,CAUlF;AAED,wBAAsB,oBAAoB,CAAC,MAAM,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAOpF;AAED,eAAO,MAAM,mBAAmB,EAAE,cAAc,CAAC,kBAAkB,CAOlE,CAAC","sourcesContent":["import type { ImageSandboxConfig, SandboxAdapter } from \"./types.js\";\nimport { SandboxError } from \"./errors.js\";\nimport { execSimple } from \"./utils.js\";\n\nexport function parseImageSandboxArg(value: string): ImageSandboxConfig | undefined {\n if (!value.startsWith(\"image:\")) {\n return undefined;\n }\n\n const image = value.slice(\"image:\".length);\n if (!image) {\n throw new SandboxError(\"Error: image sandbox requires image name (e.g., image:ubuntu:24.04)\");\n }\n return { type: \"image\", image };\n}\n\nexport async function validateImageSandbox(config: ImageSandboxConfig): Promise<void> {\n try {\n await execSimple(\"docker\", [\"--version\"]);\n } catch {\n throw new SandboxError(\"Error: Docker is not installed or not in PATH\");\n }\n console.log(` Image auto-provisioning enabled. Image: ${config.image}`);\n}\n\nexport const imageSandboxAdapter: SandboxAdapter<ImageSandboxConfig> = {\n type: \"image\",\n parse: parseImageSandboxArg,\n validate: validateImageSandbox,\n createExecutor: () => {\n throw new SandboxError(\"Error: image sandbox must resolve to a concrete container executor\");\n },\n};\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { SandboxError } from "./errors.js";
|
|
2
|
+
import { execSimple } from "./utils.js";
|
|
3
|
+
export function parseImageSandboxArg(value) {
|
|
4
|
+
if (!value.startsWith("image:")) {
|
|
5
|
+
return undefined;
|
|
6
|
+
}
|
|
7
|
+
const image = value.slice("image:".length);
|
|
8
|
+
if (!image) {
|
|
9
|
+
throw new SandboxError("Error: image sandbox requires image name (e.g., image:ubuntu:24.04)");
|
|
10
|
+
}
|
|
11
|
+
return { type: "image", image };
|
|
12
|
+
}
|
|
13
|
+
export async function validateImageSandbox(config) {
|
|
14
|
+
try {
|
|
15
|
+
await execSimple("docker", ["--version"]);
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
throw new SandboxError("Error: Docker is not installed or not in PATH");
|
|
19
|
+
}
|
|
20
|
+
console.log(` Image auto-provisioning enabled. Image: ${config.image}`);
|
|
21
|
+
}
|
|
22
|
+
export const imageSandboxAdapter = {
|
|
23
|
+
type: "image",
|
|
24
|
+
parse: parseImageSandboxArg,
|
|
25
|
+
validate: validateImageSandbox,
|
|
26
|
+
createExecutor: () => {
|
|
27
|
+
throw new SandboxError("Error: image sandbox must resolve to a concrete container executor");
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=image.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image.js","sourceRoot":"","sources":["../../src/sandbox/image.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,MAAM,UAAU,oBAAoB,CAAC,KAAa;IAChD,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QAChC,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC3C,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,YAAY,CAAC,qEAAqE,CAAC,CAAC;IAChG,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;AAClC,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,MAA0B;IACnE,IAAI,CAAC;QACH,MAAM,UAAU,CAAC,QAAQ,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC;IAC5C,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,YAAY,CAAC,+CAA+C,CAAC,CAAC;IAC1E,CAAC;IACD,OAAO,CAAC,GAAG,CAAC,6CAA6C,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC;AAC3E,CAAC;AAED,MAAM,CAAC,MAAM,mBAAmB,GAAuC;IACrE,IAAI,EAAE,OAAO;IACb,KAAK,EAAE,oBAAoB;IAC3B,QAAQ,EAAE,oBAAoB;IAC9B,cAAc,EAAE,GAAG,EAAE;QACnB,MAAM,IAAI,YAAY,CAAC,oEAAoE,CAAC,CAAC;IAC/F,CAAC;CACF,CAAC","sourcesContent":["import type { ImageSandboxConfig, SandboxAdapter } from \"./types.js\";\nimport { SandboxError } from \"./errors.js\";\nimport { execSimple } from \"./utils.js\";\n\nexport function parseImageSandboxArg(value: string): ImageSandboxConfig | undefined {\n if (!value.startsWith(\"image:\")) {\n return undefined;\n }\n\n const image = value.slice(\"image:\".length);\n if (!image) {\n throw new SandboxError(\"Error: image sandbox requires image name (e.g., image:ubuntu:24.04)\");\n }\n return { type: \"image\", image };\n}\n\nexport async function validateImageSandbox(config: ImageSandboxConfig): Promise<void> {\n try {\n await execSimple(\"docker\", [\"--version\"]);\n } catch {\n throw new SandboxError(\"Error: Docker is not installed or not in PATH\");\n }\n console.log(` Image auto-provisioning enabled. Image: ${config.image}`);\n}\n\nexport const imageSandboxAdapter: SandboxAdapter<ImageSandboxConfig> = {\n type: \"image\",\n parse: parseImageSandboxArg,\n validate: validateImageSandbox,\n createExecutor: () => {\n throw new SandboxError(\"Error: image sandbox must resolve to a concrete container executor\");\n },\n};\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ContainerExecutor } from "./container.js";
|
|
2
|
+
import { FirecrackerExecutor } from "./firecracker.js";
|
|
3
|
+
import { HostExecutor } from "./host.js";
|
|
4
|
+
import type { Executor, SandboxAdapter, SandboxConfig } from "./types.js";
|
|
5
|
+
export type { ContainerSandboxConfig, ExecOptions, ExecResult, Executor, FirecrackerSandboxConfig, HostSandboxConfig, ImageSandboxConfig, SandboxAdapter, SandboxConfig, } from "./types.js";
|
|
6
|
+
export { ContainerExecutor, FirecrackerExecutor, HostExecutor };
|
|
7
|
+
export { SandboxError } from "./errors.js";
|
|
8
|
+
export { buildContainerExecCommand, containerSandboxAdapter, parseContainerSandboxArg, validateContainerSandbox, } from "./container.js";
|
|
9
|
+
export { firecrackerSandboxAdapter, parseFirecrackerSandboxArg, validateFirecrackerSandbox, } from "./firecracker.js";
|
|
10
|
+
export { hostSandboxAdapter, parseHostSandboxArg, validateHostSandbox } from "./host.js";
|
|
11
|
+
export { imageSandboxAdapter, parseImageSandboxArg, validateImageSandbox } from "./image.js";
|
|
12
|
+
declare const sandboxAdapters: readonly [SandboxAdapter<import("./types.js").HostSandboxConfig>, SandboxAdapter<import("./types.js").ContainerSandboxConfig>, SandboxAdapter<import("./types.js").ImageSandboxConfig>, SandboxAdapter<import("./types.js").FirecrackerSandboxConfig>];
|
|
13
|
+
export declare function getSandboxAdapters(): readonly [...typeof sandboxAdapters];
|
|
14
|
+
export declare function parseSandboxArg(value: string): SandboxConfig;
|
|
15
|
+
export declare function validateSandbox(config: SandboxConfig): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Create an executor that runs commands on host, in a Docker container, or in a Firecracker VM.
|
|
18
|
+
*/
|
|
19
|
+
export declare function createExecutor(config: SandboxConfig, env?: Record<string, string>, ensureReady?: () => Promise<void>): Executor;
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sandbox/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EAIlB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,mBAAmB,EAIpB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,YAAY,EAIb,MAAM,WAAW,CAAC;AAGnB,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE1E,YAAY,EACV,sBAAsB,EACtB,WAAW,EACX,UAAU,EACV,QAAQ,EACR,wBAAwB,EACxB,iBAAiB,EACjB,kBAAkB,EAClB,cAAc,EACd,aAAa,GACd,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,YAAY,EAAE,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EACL,yBAAyB,EACzB,uBAAuB,EACvB,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,yBAAyB,EACzB,0BAA0B,EAC1B,0BAA0B,GAC3B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACzF,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAE7F,QAAA,MAAM,eAAe,wPAKX,CAAC;AAKX,wBAAgB,kBAAkB,IAAI,SAAS,CAAC,GAAG,OAAO,eAAe,CAAC,CAEzE;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,aAAa,CAiB5D;AAED,wBAAsB,eAAe,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAO1E;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,aAAa,EACrB,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC5B,WAAW,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAChC,QAAQ,CAMV","sourcesContent":["import {\n ContainerExecutor,\n containerSandboxAdapter,\n parseContainerSandboxArg,\n validateContainerSandbox,\n} from \"./container.js\";\nimport {\n FirecrackerExecutor,\n firecrackerSandboxAdapter,\n parseFirecrackerSandboxArg,\n validateFirecrackerSandbox,\n} from \"./firecracker.js\";\nimport {\n HostExecutor,\n hostSandboxAdapter,\n parseHostSandboxArg,\n validateHostSandbox,\n} from \"./host.js\";\nimport { imageSandboxAdapter, parseImageSandboxArg, validateImageSandbox } from \"./image.js\";\nimport { SandboxError } from \"./errors.js\";\nimport type { Executor, SandboxAdapter, SandboxConfig } from \"./types.js\";\n\nexport type {\n ContainerSandboxConfig,\n ExecOptions,\n ExecResult,\n Executor,\n FirecrackerSandboxConfig,\n HostSandboxConfig,\n ImageSandboxConfig,\n SandboxAdapter,\n SandboxConfig,\n} from \"./types.js\";\nexport { ContainerExecutor, FirecrackerExecutor, HostExecutor };\nexport { SandboxError } from \"./errors.js\";\nexport {\n buildContainerExecCommand,\n containerSandboxAdapter,\n parseContainerSandboxArg,\n validateContainerSandbox,\n} from \"./container.js\";\nexport {\n firecrackerSandboxAdapter,\n parseFirecrackerSandboxArg,\n validateFirecrackerSandbox,\n} from \"./firecracker.js\";\nexport { hostSandboxAdapter, parseHostSandboxArg, validateHostSandbox } from \"./host.js\";\nexport { imageSandboxAdapter, parseImageSandboxArg, validateImageSandbox } from \"./image.js\";\n\nconst sandboxAdapters = [\n hostSandboxAdapter,\n containerSandboxAdapter,\n imageSandboxAdapter,\n firecrackerSandboxAdapter,\n] as const;\nconst sandboxAdapterByType = new Map(\n sandboxAdapters.map((adapter) => [adapter.type, adapter]),\n) as Map<SandboxConfig[\"type\"], SandboxAdapter>;\n\nexport function getSandboxAdapters(): readonly [...typeof sandboxAdapters] {\n return sandboxAdapters;\n}\n\nexport function parseSandboxArg(value: string): SandboxConfig {\n for (const adapter of sandboxAdapters) {\n const config = adapter.parse(value);\n if (config) {\n return config;\n }\n }\n\n if (value.startsWith(\"docker:\")) {\n throw new SandboxError(\n `Error: '${value}' is not supported. Use 'container:<container-name>' for the shared-container mode or 'image:<image-name>' for mama-managed per-user containers.`,\n );\n }\n\n throw new SandboxError(\n `Error: Invalid sandbox type '${value}'. Use 'host', 'container:<container-name>', 'image:<image-name>', or 'firecracker:<vm-id>:<host-path>'`,\n );\n}\n\nexport async function validateSandbox(config: SandboxConfig): Promise<void> {\n const adapter = sandboxAdapterByType.get(config.type);\n if (!adapter) {\n throw new SandboxError(`Error: Unsupported sandbox type '${config.type}'`);\n }\n\n await adapter.validate(config);\n}\n\n/**\n * Create an executor that runs commands on host, in a Docker container, or in a Firecracker VM.\n */\nexport function createExecutor(\n config: SandboxConfig,\n env?: Record<string, string>,\n ensureReady?: () => Promise<void>,\n): Executor {\n const adapter = sandboxAdapterByType.get(config.type);\n if (!adapter) {\n throw new SandboxError(`Error: Unsupported sandbox type '${config.type}'`);\n }\n return adapter.createExecutor(config, env, ensureReady);\n}\n"]}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ContainerExecutor, containerSandboxAdapter, } from "./container.js";
|
|
2
|
+
import { FirecrackerExecutor, firecrackerSandboxAdapter, } from "./firecracker.js";
|
|
3
|
+
import { HostExecutor, hostSandboxAdapter, } from "./host.js";
|
|
4
|
+
import { imageSandboxAdapter } from "./image.js";
|
|
5
|
+
import { SandboxError } from "./errors.js";
|
|
6
|
+
export { ContainerExecutor, FirecrackerExecutor, HostExecutor };
|
|
7
|
+
export { SandboxError } from "./errors.js";
|
|
8
|
+
export { buildContainerExecCommand, containerSandboxAdapter, parseContainerSandboxArg, validateContainerSandbox, } from "./container.js";
|
|
9
|
+
export { firecrackerSandboxAdapter, parseFirecrackerSandboxArg, validateFirecrackerSandbox, } from "./firecracker.js";
|
|
10
|
+
export { hostSandboxAdapter, parseHostSandboxArg, validateHostSandbox } from "./host.js";
|
|
11
|
+
export { imageSandboxAdapter, parseImageSandboxArg, validateImageSandbox } from "./image.js";
|
|
12
|
+
const sandboxAdapters = [
|
|
13
|
+
hostSandboxAdapter,
|
|
14
|
+
containerSandboxAdapter,
|
|
15
|
+
imageSandboxAdapter,
|
|
16
|
+
firecrackerSandboxAdapter,
|
|
17
|
+
];
|
|
18
|
+
const sandboxAdapterByType = new Map(sandboxAdapters.map((adapter) => [adapter.type, adapter]));
|
|
19
|
+
export function getSandboxAdapters() {
|
|
20
|
+
return sandboxAdapters;
|
|
21
|
+
}
|
|
22
|
+
export function parseSandboxArg(value) {
|
|
23
|
+
for (const adapter of sandboxAdapters) {
|
|
24
|
+
const config = adapter.parse(value);
|
|
25
|
+
if (config) {
|
|
26
|
+
return config;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (value.startsWith("docker:")) {
|
|
30
|
+
throw new SandboxError(`Error: '${value}' is not supported. Use 'container:<container-name>' for the shared-container mode or 'image:<image-name>' for mama-managed per-user containers.`);
|
|
31
|
+
}
|
|
32
|
+
throw new SandboxError(`Error: Invalid sandbox type '${value}'. Use 'host', 'container:<container-name>', 'image:<image-name>', or 'firecracker:<vm-id>:<host-path>'`);
|
|
33
|
+
}
|
|
34
|
+
export async function validateSandbox(config) {
|
|
35
|
+
const adapter = sandboxAdapterByType.get(config.type);
|
|
36
|
+
if (!adapter) {
|
|
37
|
+
throw new SandboxError(`Error: Unsupported sandbox type '${config.type}'`);
|
|
38
|
+
}
|
|
39
|
+
await adapter.validate(config);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Create an executor that runs commands on host, in a Docker container, or in a Firecracker VM.
|
|
43
|
+
*/
|
|
44
|
+
export function createExecutor(config, env, ensureReady) {
|
|
45
|
+
const adapter = sandboxAdapterByType.get(config.type);
|
|
46
|
+
if (!adapter) {
|
|
47
|
+
throw new SandboxError(`Error: Unsupported sandbox type '${config.type}'`);
|
|
48
|
+
}
|
|
49
|
+
return adapter.createExecutor(config, env, ensureReady);
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/sandbox/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,uBAAuB,GAGxB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,mBAAmB,EACnB,yBAAyB,GAG1B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,YAAY,EACZ,kBAAkB,GAGnB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,mBAAmB,EAA8C,MAAM,YAAY,CAAC;AAC7F,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAc3C,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,YAAY,EAAE,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EACL,yBAAyB,EACzB,uBAAuB,EACvB,wBAAwB,EACxB,wBAAwB,GACzB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,yBAAyB,EACzB,0BAA0B,EAC1B,0BAA0B,GAC3B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACzF,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAE7F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AAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,YAAY,CAAC,oCAAoC,MAAM,CAAC,IAAI,GAAG,CAAC,CAAC;IAC7E,CAAC;IACD,OAAO,OAAO,CAAC,cAAc,CAAC,MAAM,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC;AAC1D,CAAC","sourcesContent":["import {\n ContainerExecutor,\n containerSandboxAdapter,\n parseContainerSandboxArg,\n validateContainerSandbox,\n} from \"./container.js\";\nimport {\n FirecrackerExecutor,\n firecrackerSandboxAdapter,\n parseFirecrackerSandboxArg,\n validateFirecrackerSandbox,\n} from \"./firecracker.js\";\nimport {\n HostExecutor,\n hostSandboxAdapter,\n parseHostSandboxArg,\n validateHostSandbox,\n} from \"./host.js\";\nimport { imageSandboxAdapter, parseImageSandboxArg, validateImageSandbox } from \"./image.js\";\nimport { SandboxError } from \"./errors.js\";\nimport type { Executor, SandboxAdapter, SandboxConfig } from \"./types.js\";\n\nexport type {\n ContainerSandboxConfig,\n ExecOptions,\n ExecResult,\n Executor,\n FirecrackerSandboxConfig,\n HostSandboxConfig,\n ImageSandboxConfig,\n SandboxAdapter,\n SandboxConfig,\n} from \"./types.js\";\nexport { ContainerExecutor, FirecrackerExecutor, HostExecutor };\nexport { SandboxError } from \"./errors.js\";\nexport {\n buildContainerExecCommand,\n containerSandboxAdapter,\n parseContainerSandboxArg,\n validateContainerSandbox,\n} from \"./container.js\";\nexport {\n firecrackerSandboxAdapter,\n parseFirecrackerSandboxArg,\n validateFirecrackerSandbox,\n} from \"./firecracker.js\";\nexport { hostSandboxAdapter, parseHostSandboxArg, validateHostSandbox } from \"./host.js\";\nexport { imageSandboxAdapter, parseImageSandboxArg, validateImageSandbox } from \"./image.js\";\n\nconst sandboxAdapters = [\n hostSandboxAdapter,\n containerSandboxAdapter,\n imageSandboxAdapter,\n firecrackerSandboxAdapter,\n] as const;\nconst sandboxAdapterByType = new Map(\n sandboxAdapters.map((adapter) => [adapter.type, adapter]),\n) as Map<SandboxConfig[\"type\"], SandboxAdapter>;\n\nexport function getSandboxAdapters(): readonly [...typeof sandboxAdapters] {\n return sandboxAdapters;\n}\n\nexport function parseSandboxArg(value: string): SandboxConfig {\n for (const adapter of sandboxAdapters) {\n const config = adapter.parse(value);\n if (config) {\n return config;\n }\n }\n\n if (value.startsWith(\"docker:\")) {\n throw new SandboxError(\n `Error: '${value}' is not supported. Use 'container:<container-name>' for the shared-container mode or 'image:<image-name>' for mama-managed per-user containers.`,\n );\n }\n\n throw new SandboxError(\n `Error: Invalid sandbox type '${value}'. Use 'host', 'container:<container-name>', 'image:<image-name>', or 'firecracker:<vm-id>:<host-path>'`,\n );\n}\n\nexport async function validateSandbox(config: SandboxConfig): Promise<void> {\n const adapter = sandboxAdapterByType.get(config.type);\n if (!adapter) {\n throw new SandboxError(`Error: Unsupported sandbox type '${config.type}'`);\n }\n\n await adapter.validate(config);\n}\n\n/**\n * Create an executor that runs commands on host, in a Docker container, or in a Firecracker VM.\n */\nexport function createExecutor(\n config: SandboxConfig,\n env?: Record<string, string>,\n ensureReady?: () => Promise<void>,\n): Executor {\n const adapter = sandboxAdapterByType.get(config.type);\n if (!adapter) {\n throw new SandboxError(`Error: Unsupported sandbox type '${config.type}'`);\n }\n return adapter.createExecutor(config, env, ensureReady);\n}\n"]}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
export type SandboxConfig = HostSandboxConfig | ContainerSandboxConfig | ImageSandboxConfig | FirecrackerSandboxConfig;
|
|
2
|
+
export interface HostSandboxConfig {
|
|
3
|
+
type: "host";
|
|
4
|
+
}
|
|
5
|
+
export interface ContainerSandboxConfig {
|
|
6
|
+
type: "container";
|
|
7
|
+
container: string;
|
|
8
|
+
}
|
|
9
|
+
export interface ImageSandboxConfig {
|
|
10
|
+
type: "image";
|
|
11
|
+
image: string;
|
|
12
|
+
}
|
|
13
|
+
export interface FirecrackerSandboxConfig {
|
|
14
|
+
type: "firecracker";
|
|
15
|
+
vmId: string;
|
|
16
|
+
hostPath: string;
|
|
17
|
+
sshUser?: string;
|
|
18
|
+
sshPort?: number;
|
|
19
|
+
}
|
|
20
|
+
export interface Executor {
|
|
21
|
+
/**
|
|
22
|
+
* Execute a bash command.
|
|
23
|
+
*/
|
|
24
|
+
exec(command: string, options?: ExecOptions): Promise<ExecResult>;
|
|
25
|
+
/**
|
|
26
|
+
* Get the workspace path prefix for this executor.
|
|
27
|
+
* Host: returns the actual path.
|
|
28
|
+
* Container/Firecracker: returns /workspace.
|
|
29
|
+
*/
|
|
30
|
+
getWorkspacePath(hostPath: string): string;
|
|
31
|
+
/**
|
|
32
|
+
* Get the current sandbox config used by this executor.
|
|
33
|
+
*/
|
|
34
|
+
getSandboxConfig(): SandboxConfig;
|
|
35
|
+
}
|
|
36
|
+
export interface ExecOptions {
|
|
37
|
+
timeout?: number;
|
|
38
|
+
signal?: AbortSignal;
|
|
39
|
+
}
|
|
40
|
+
export interface ExecResult {
|
|
41
|
+
stdout: string;
|
|
42
|
+
stderr: string;
|
|
43
|
+
code: number;
|
|
44
|
+
}
|
|
45
|
+
export interface SandboxAdapter<TConfig extends SandboxConfig = SandboxConfig> {
|
|
46
|
+
type: TConfig["type"];
|
|
47
|
+
parse(value: string): TConfig | undefined;
|
|
48
|
+
validate(config: TConfig): Promise<void>;
|
|
49
|
+
createExecutor(config: TConfig, env?: Record<string, string>, ensureReady?: () => Promise<void>): Executor;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/sandbox/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GACrB,iBAAiB,GACjB,sBAAsB,GACtB,kBAAkB,GAClB,wBAAwB,CAAC;AAE7B,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,WAAW,CAAC;IAClB,SAAS,E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n | HostSandboxConfig\n | ContainerSandboxConfig\n | ImageSandboxConfig\n | FirecrackerSandboxConfig;\n\nexport interface HostSandboxConfig {\n type: \"host\";\n}\n\nexport interface ContainerSandboxConfig {\n type: \"container\";\n container: string;\n}\n\nexport interface ImageSandboxConfig {\n type: \"image\";\n image: string;\n}\n\nexport interface FirecrackerSandboxConfig {\n type: \"firecracker\";\n vmId: string;\n hostPath: string;\n sshUser?: string;\n sshPort?: number;\n}\n\nexport interface Executor {\n /**\n * Execute a bash command.\n */\n exec(command: string, options?: ExecOptions): Promise<ExecResult>;\n\n /**\n * Get the workspace path prefix for this executor.\n * Host: returns the actual path.\n * Container/Firecracker: returns /workspace.\n */\n getWorkspacePath(hostPath: string): string;\n\n /**\n * Get the current sandbox config used by this executor.\n */\n getSandboxConfig(): SandboxConfig;\n}\n\nexport interface ExecOptions {\n timeout?: number;\n signal?: AbortSignal;\n}\n\nexport interface ExecResult {\n stdout: string;\n stderr: string;\n code: number;\n}\n\nexport interface SandboxAdapter<TConfig extends SandboxConfig = SandboxConfig> {\n type: TConfig[\"type\"];\n parse(value: string): TConfig | undefined;\n validate(config: TConfig): Promise<void>;\n createExecutor(\n config: TConfig,\n env?: Record<string, string>,\n ensureReady?: () => Promise<void>,\n ): Executor;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/sandbox/types.ts"],"names":[],"mappings":"","sourcesContent":["export type SandboxConfig =\n | HostSandboxConfig\n | ContainerSandboxConfig\n | ImageSandboxConfig\n | FirecrackerSandboxConfig;\n\nexport interface HostSandboxConfig {\n type: \"host\";\n}\n\nexport interface ContainerSandboxConfig {\n type: \"container\";\n container: string;\n}\n\nexport interface ImageSandboxConfig {\n type: \"image\";\n image: string;\n}\n\nexport interface FirecrackerSandboxConfig {\n type: \"firecracker\";\n vmId: string;\n hostPath: string;\n sshUser?: string;\n sshPort?: number;\n}\n\nexport interface Executor {\n /**\n * Execute a bash command.\n */\n exec(command: string, options?: ExecOptions): Promise<ExecResult>;\n\n /**\n * Get the workspace path prefix for this executor.\n * Host: returns the actual path.\n * Container/Firecracker: returns /workspace.\n */\n getWorkspacePath(hostPath: string): string;\n\n /**\n * Get the current sandbox config used by this executor.\n */\n getSandboxConfig(): SandboxConfig;\n}\n\nexport interface ExecOptions {\n timeout?: number;\n signal?: AbortSignal;\n}\n\nexport interface ExecResult {\n stdout: string;\n stderr: string;\n code: number;\n}\n\nexport interface SandboxAdapter<TConfig extends SandboxConfig = SandboxConfig> {\n type: TConfig[\"type\"];\n parse(value: string): TConfig | undefined;\n validate(config: TConfig): Promise<void>;\n createExecutor(\n config: TConfig,\n env?: Record<string, string>,\n ensureReady?: () => Promise<void>,\n ): Executor;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/sandbox/utils.ts"],"names":[],"mappings":"AAEA,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAgBvE;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAqBjD;AAED,wBAAgB,WAAW,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAG7C","sourcesContent":["import { spawn } from \"child_process\";\n\nexport function execSimple(cmd: string, args: string[]): Promise<string> {\n return new Promise((resolve, reject) => {\n const child = spawn(cmd, args, { stdio: [\"ignore\", \"pipe\", \"pipe\"] });\n let stdout = \"\";\n let stderr = \"\";\n child.stdout?.on(\"data\", (d) => {\n stdout += d;\n });\n child.stderr?.on(\"data\", (d) => {\n stderr += d;\n });\n child.on(\"close\", (code) => {\n if (code === 0) resolve(stdout);\n else reject(new Error(stderr || `Exit code ${code}`));\n });\n });\n}\n\nexport function killProcessTree(pid: number): void {\n if (process.platform === \"win32\") {\n try {\n spawn(\"taskkill\", [\"/F\", \"/T\", \"/PID\", String(pid)], {\n stdio: \"ignore\",\n detached: true,\n });\n } catch {\n // Ignore errors\n }\n } else {\n try {\n process.kill(-pid, \"SIGKILL\");\n } catch {\n try {\n process.kill(pid, \"SIGKILL\");\n } catch {\n // Process already dead\n }\n }\n }\n}\n\nexport function shellEscape(s: string): string {\n // Escape for passing to sh -c\n return `'${s.replace(/'/g, \"'\\\\''\")}'`;\n}\n"]}
|