Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(bot-box): give the box the machine's CPU list so Antigravity starts on a Cloud
milind-soni551a507784f6
diff --git a/docs/bot-box.md b/docs/bot-box.mdindex c7739151d0..49034e536c 100644--- a/docs/bot-box.md+++ b/docs/bot-box.md@@ -15,6 +15,7 @@ its database, its settings, other bots' folders and other turns' processes are n| put back inside it: the turn's working folder and the bot's own folder (`workspaces/<bot>`), read-write | What the turn works on, and the bot's memory and skills || put back: this turn's permission socket (the engine's question and approval helper reaches the server through it), and, read-only, the conversation's own hook token folder (the hook helper's bearer, renewed each turn) and the files its command line names (MCP config, system prompt) | What the driver made for this one process || private `/tmp`, `/var/tmp`, `/run`, `/dev`, `/proc` | Its own PID namespace: other turns' processes do not exist for it |+| `/sys/devices/system/cpu/possible` and `online`, read-only; nothing else of `/sys` | The machine's CPU count. Programs built with TCMalloc (Google's Antigravity runtime) stop themselves at start without it (exit 134) || a network namespace with loopback only | Two loopback ports are bridged to unix sockets from outside (below); nothing else on the machine's loopback is reachable, and there is no route out |The environment is an allow-list (`server/bot-box/env.ts`): the engine's own settings and keys, the harness capabilitydiff --git a/server/bot-box/box-probe.ts b/server/bot-box/box-probe.tsindex 544475f5ba..1ba4a96255 100644--- a/server/bot-box/box-probe.ts+++ b/server/bot-box/box-probe.ts@@ -36,6 +36,8 @@ export interface ProbeSpec {publicTarget: string | null;/** Checks that apply only when the box has its own network. */isolatedNet: boolean;+ /** The host has a CPU list (`/sys/devices/system/cpu/possible`), so the box must have it too (plan.ts CPU_LIST_FILES). */+ cpuList?: boolean;/** T0c: the seccomp filter is on, so a kernel-keyring call must fail with EPERM (an unprivileged process may make it otherwise). */seccomp?: boolean;/** T0b: a model call through the broker, and the real key's value that must be nowhere in the box. */@@ -130,6 +132,11 @@ export async function runProbe(spec: ProbeSpec, env: Record<string, string | undadd("engine-read-only", existsSync(join(spec.engine.bin, spec.engine.name)) && tamper.failed, tamper.code);add("tmp-private", !existsSync(spec.hostTmpFile), existsSync(spec.hostTmpFile) ? "host /tmp visible" : "private");add("hostname-private", hostname() === "omb-box", hostname() === "omb-box" ? "omb-box" : "host name visible");+ if (spec.cpuList) {+ // TCMalloc runtimes (Google's Antigravity) stop at start without it: exit 134.+ const cpus = fails(() => { if (!/^\d/.test(readFileSync("/sys/devices/system/cpu/possible", "utf8"))) throw new Error("empty"); });+ add("cpu-list-readable", !cpus.failed, cpus.code);+ }add("harness-internal-allowed", (await httpStatus(spec.harnessPort, "/api/internal/box-probe")) === "200", "GET /api/internal/box-probe");add("harness-other-refused", (await httpStatus(spec.harnessPort, "/api/bots")) === "403", "GET /api/bots");diff --git a/server/bot-box/plan.test.ts b/server/bot-box/plan.test.tsindex a2cb98e926..0e15cd0bea 100644--- a/server/bot-box/plan.test.ts+++ b/server/bot-box/plan.test.ts@@ -2,7 +2,7 @@ import { join } from "node:path";import { describe, expect, it } from "vitest";import { engineInstallRoots } from "../engine-roots.ts";-import { BOX_MUTATIONS, argvPaths, bwrapArgs, planBox, taskWorkspaceIds, visibleInBox, type BoxMutation, type BoxSetup } from "./plan.ts";+import { BOX_MUTATIONS, CPU_LIST_FILES, argvPaths, bwrapArgs, planBox, taskWorkspaceIds, visibleInBox, type BoxMutation, type BoxSetup } from "./plan.ts";const home = "/data";const dataDir = "/data/.openmausbot";@@ -112,6 +112,22 @@ linuxBox("the box plan", () => {expect(visibleInBox(plan, "/data/.openmausbot/messages.db")).toBe("none");});+ it("has the machine's CPU list read-only and nothing else of /sys, so a TCMalloc runtime (Antigravity) can start", () => {+ // Measured on a Fly Cloud home (2, 4 and 8 shared CPUs): without `possible` Google's runtime stops at start with+ // "tcmalloc/internal/sysinfo.h:76] CHECK in NumCPUs" and exit 134; with it, initialize answers.+ const command = join(dataDir, "tools", "antigravity-acp", "linux-x64", "versions", "abc", "agy_acp_server.par");+ for (const plan of [turn(), planBox(setup(), { command, args: ["--uid="], cwd, env: { HOME: home } })]) {+ expect(visibleInBox(plan, "/sys/devices/system/cpu/possible")).toBe("ro");+ expect(visibleInBox(plan, "/sys/devices/system/cpu/online")).toBe("ro");+ for (const hidden of ["/sys/devices/system/cpu/vulnerabilities/spectre_v2", "/sys/class/net/eth0/address", "/sys/fs/cgroup/memory.max", "/sys/kernel/mm"]) {+ expect(visibleInBox(plan, hidden), hidden).toBe("none");+ }+ const text = bwrapArgs(plan).join(" ");+ for (const file of CPU_LIST_FILES) expect(text).toContain(`--ro-bind-try ${file} ${file}`);+ expect(text).not.toMatch(/--(?:ro-)?bind(?:-try)? \/sys /);+ }+ });+it("Antigravity's own profile (GEMINI_HOME) goes back read-write, and no other account's", () => {const profile = join(dataDir, "providers", "antigravity", "a".repeat(64));const plan = planBox(setup(), { command: join(dataDir, "tools", "antigravity-acp", "linux-x64", "versions", "abc", "agy_acp_server"), args: ["--uid="], cwd, env: { HOME: home, GEMINI_HOME: profile } });diff --git a/server/bot-box/plan.ts b/server/bot-box/plan.tsindex 98072b8eed..492e6527d1 100644--- a/server/bot-box/plan.ts+++ b/server/bot-box/plan.ts@@ -13,6 +13,7 @@// bot's own SOUL.md (bots/<bot>/SOUL.md, which it may read but never write) and the engines OpenMausBot installed// there, whole, since npm's bin links point into the prefix by relative paths;// - a private /proc (its own PID namespace: other turns' processes do not exist for it), /dev, /tmp and /run;+// - of /sys, only the machine's CPU list, read-only;// - a network namespace with loopback only. Two loopback ports inside are bridged to unix sockets bound in from outside:// the egress gate (every connection to the internet goes through it) and the harness gate (only /api/internal/// routes of this server). Nothing else on the server's loopback is reachable.@@ -118,6 +119,10 @@ export function argvPaths(args: readonly string[]): string[] {/** Environment values that name folders the engine writes: its own config and caches. */export const PATH_ENV_NAMES = ["CLAUDE_CONFIG_DIR", "CODEX_HOME", "XDG_CONFIG_HOME", "XDG_DATA_HOME", "XDG_CACHE_HOME", "GROK_HOME", "OPENCODE_HOME", "HERMES_HOME", "GEMINI_HOME", "TMPDIR"] as const;+/** The only part of /sys the box has: how many CPUs the machine has. Programs built with TCMalloc (Google's Antigravity+ * runtime) read `possible` at start and stop themselves (SIGABRT, exit 134) when it is missing. */+export const CPU_LIST_FILES = ["/sys/devices/system/cpu/possible", "/sys/devices/system/cpu/online"] as const;+/** Folders the box always has its own copy of, so no setting may put the host's back. */const PRIVATE_INSIDE = ["/tmp", "/var/tmp", "/run", "/dev", "/proc"];@@ -134,6 +139,7 @@ export function planBox(setup: BoxSetup, request: BoxRequest): BoxPlan {{ kind: "ro", source: "/etc", target: "/etc" },{ kind: "ro", source: "/opt", target: "/opt", optional: true },{ kind: "ro", source: "/var/lib", target: "/var/lib", optional: true },+ ...CPU_LIST_FILES.map((file): Mount => ({ kind: "ro", source: file, target: file, optional: true })),];for (const root of setup.codeRoots) {const code = resolve(root);diff --git a/server/bot-box/self-check.linux.test.ts b/server/bot-box/self-check.linux.test.tsindex f02a5cc581..8e799e052e 100644--- a/server/bot-box/self-check.linux.test.ts+++ b/server/bot-box/self-check.linux.test.ts@@ -25,8 +25,8 @@ describe.skipIf(!available)(`the real box (${detection.box === "bwrap" ? "bubbleconst result = await runBoxSelfCheck(options());expect(result.error).toBeUndefined();expect(result.failed).toEqual([]);- expect(result.total).toBe(process.arch === "x64" ? 31 : 30);- expect(result.results.map((check) => check.id)).toEqual(expect.arrayContaining(["engine-runs", "engine-read-only", "no-provider-key-in-env", "broker-call-works", "broker-wrong-token-refused", "broker-other-grant-refused", "broker-key-not-on-disk", "base-url-is-broker"]));+ expect(result.total).toBe(process.arch === "x64" ? 32 : 31);+ expect(result.results.map((check) => check.id)).toEqual(expect.arrayContaining(["engine-runs", "engine-read-only", "cpu-list-readable", "no-provider-key-in-env", "broker-call-works", "broker-wrong-token-refused", "broker-other-grant-refused", "broker-key-not-on-disk", "base-url-is-broker"]));}, 120_000);it("each mutation fails the checks it guards, and only those", async () => {diff --git a/server/bot-box/self-check.ts b/server/bot-box/self-check.tsindex 6c11319e7f..2025286dd4 100644--- a/server/bot-box/self-check.ts+++ b/server/bot-box/self-check.ts@@ -133,6 +133,7 @@ export async function runBoxSelfCheck(options: SelfCheckOptions): Promise<SelfChharnessPort: serverPort, egressPort: BOX_EGRESS_PORT, privatePort, publicTarget, isolatedNet,// Checked whenever a filter is in the setup: the no-seccomp mutation leaves it out of the box, so the check must fail.seccomp: Boolean(options.seccompFile),+ cpuList: existsSync("/sys/devices/system/cpu/possible"),};const wrapped = runner.wrap({command: process.execPath, args: [options.probeScript ?? BOX_PROBE_SCRIPT], cwd, botId: "probe",