fix: add OpenSSL build for musl in runtime Dockerfile

This commit is contained in:
Nathan Flurry 2026-01-28 01:23:51 -08:00
parent 6aa591bd91
commit 5dd8a13845
16 changed files with 262 additions and 376 deletions

View file

@ -1,89 +1,32 @@
import { Sandbox } from "@e2b/code-interpreter";
import { pathToFileURL } from "node:url";
import {
ensureUrl,
logInspectorUrl,
runPrompt,
waitForHealth,
} from "@sandbox-agent/example-shared";
import { logInspectorUrl, runPrompt } from "@sandbox-agent/example-shared";
const INSTALL_SCRIPT = "curl -fsSL https://releases.rivet.dev/sandbox-agent/latest/install.sh | sh";
const DEFAULT_PORT = 2468;
type CommandRunner = (command: string, options?: Record<string, unknown>) => Promise<unknown>;
function resolveCommandRunner(sandbox: Sandbox): CommandRunner {
if (sandbox.commands?.run) {
return sandbox.commands.run.bind(sandbox.commands);
}
if (sandbox.commands?.exec) {
return sandbox.commands.exec.bind(sandbox.commands);
}
throw new Error("E2B SDK does not expose commands.run or commands.exec");
if (!process.env.E2B_API_KEY || (!process.env.OPENAI_API_KEY && !process.env.ANTHROPIC_API_KEY)) {
throw new Error("E2B_API_KEY and (OPENAI_API_KEY or ANTHROPIC_API_KEY) required");
}
export async function setupE2BSandboxAgent(): Promise<{
baseUrl: string;
token: string;
cleanup: () => Promise<void>;
}> {
const token = process.env.SANDBOX_TOKEN || "";
const port = Number.parseInt(process.env.SANDBOX_PORT || "", 10) || DEFAULT_PORT;
const sandbox = await Sandbox.create({ allowInternetAccess: true });
const sandbox = await Sandbox.create({
allowInternetAccess: true,
envs: token ? { SANDBOX_TOKEN: token } : undefined,
});
const run = (cmd: string) => sandbox.commands.run(cmd);
const runCommand = resolveCommandRunner(sandbox);
console.log("Installing sandbox-agent...");
await run("curl -fsSL https://releases.rivet.dev/sandbox-agent/latest/install.sh | sh");
await run("sandbox-agent install-agent claude");
await run("sandbox-agent install-agent codex");
await runCommand(`bash -lc "${INSTALL_SCRIPT}"`);
const tokenFlag = token ? "--token $SANDBOX_TOKEN" : "--no-token";
await runCommand(`bash -lc "sandbox-agent server ${tokenFlag} --host 0.0.0.0 --port ${port}"`, {
background: true,
envs: token ? { SANDBOX_TOKEN: token } : undefined,
});
console.log("Starting server...");
await sandbox.commands.run("sandbox-agent server --no-token --host 0.0.0.0 --port 3000", { background: true });
const baseUrl = ensureUrl(sandbox.getHost(port));
await waitForHealth({ baseUrl, token });
logInspectorUrl({ baseUrl, token });
const baseUrl = `https://${sandbox.getHost(3000)}`;
logInspectorUrl({ baseUrl });
const cleanup = async () => {
try {
await sandbox.kill();
} catch {
// ignore cleanup errors
}
};
const cleanup = async () => {
console.log("Cleaning up...");
await sandbox.kill();
process.exit(0);
};
process.once("SIGINT", cleanup);
process.once("SIGTERM", cleanup);
return {
baseUrl,
token,
cleanup,
};
}
async function main(): Promise<void> {
const { baseUrl, token, cleanup } = await setupE2BSandboxAgent();
const exitHandler = async () => {
await cleanup();
process.exit(0);
};
process.on("SIGINT", () => {
void exitHandler();
});
process.on("SIGTERM", () => {
void exitHandler();
});
await runPrompt({ baseUrl, token });
}
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
main().catch((error) => {
console.error(error);
process.exit(1);
});
}
await runPrompt({ baseUrl });
await cleanup();