Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Merge pull request #3835 from zicochaos/fix/bot-box-ro-hardlink

milind-sonif0171452cdbc
diff --cc server/bot-box/box.ts
index c626b66dea,16bf5600b8..0de2a40f38
--- a/server/bot-box/box.ts
+++ b/server/bot-box/box.ts
@@@ -2,8 -2,7 +2,8 @@@
// boxes reach through unix sockets (egress-gate.ts, harness-gate.ts), and wraps each bot spawn (server/procs.ts spawnCli
// with owner "bot") in bubblewrap by the plan (plan.ts). Nothing here changes a spawn when the box is off: the command,
// its arguments and its environment go through untouched, so every host that is not a Cloud home behaves as before.
-import { closeSync, existsSync, mkdirSync, openSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
+import { randomBytes } from "node:crypto";
- import { existsSync, mkdirSync, openSync, rmSync, statSync, writeFileSync } from "node:fs";
++import { closeSync, existsSync, mkdirSync, openSync, rmSync, statSync, writeFileSync } from "node:fs";
import { dirname, join, resolve } from "node:path";
import { engineInstallRoots } from "../engine-roots.ts";
@@@ -105,17 -94,23 +104,24 @@@ export class BoxRunner
: boxEnvironment(request.env, this.options.denyEnv, new Set(request.allowEnv ?? []));
if (plan.net === "isolated") {
const proxy = `http://127.0.0.1:${this.options.egressPort ?? BOX_EGRESS_PORT}`;
- for (const name of ["HTTPS_PROXY", "HTTP_PROXY", "https_proxy", "http_proxy"]) env[name] = proxy;
+ for (const name of BOX_PROXY_ENV) env[name] = proxy;
// Node's env proxy matches an IPv6 host only bracketed; curl and the engines take the plain forms.
- for (const name of ["NO_PROXY", "no_proxy"]) env[name] = "127.0.0.1,localhost,::1,[::1]";
+ for (const name of BOX_NO_PROXY_ENV) env[name] = "127.0.0.1,localhost,::1,[::1]";
}
const bridges = plan.net === "isolated" ? this.options.setup.bridges : [];
- const inner = bridgedCommand(this.options.bridge, bridges, request.command, request.args);
+ const relay = plan.net === "isolated" && request.relay ? inBoxSocket(RELAY_SOCKET_NAME) : undefined;
+ const inner = bridgedCommand(this.options.bridge, bridges, request.command, request.args, relay);
const brokered = this.broker(env, plan, request);
- const vouched = (request.allowEnv ?? []).filter((name) => /(?:KEY|TOKEN|SECRET)$/.test(name) && brokered.env[name] !== undefined && brokered.env[name] === request.env[name]);
- const unbrokered = [...new Set([...brokered.unbrokered, ...vouched])];
- return { command: this.options.bwrap, args: [...bwrapArgs(plan), "--", inner.command, ...inner.args], env: brokered.env, plan, token: brokered.token, release: brokered.release, unbrokered, extraFds };
+ try {
+ const vouched = (request.allowEnv ?? []).filter((name) => /(?:KEY|TOKEN|SECRET)$/.test(name) && brokered.env[name] !== undefined && brokered.env[name] === request.env[name]);
+ const unbrokered = [...new Set([...brokered.unbrokered, ...vouched])];
+ if (seccomp) extraFds.push(openSync(seccomp, "r"));
+ return { command: this.options.bwrap, args: [...bwrapArgs(plan), "--", inner.command, ...inner.args], env: brokered.env, plan, token: brokered.token, release: brokered.release, unbrokered, extraFds };
+ } catch (error) {
+ for (const fd of extraFds) { try { closeSync(fd); } catch {} }
+ brokered.release();
+ throw error;
+ }
}
/** Keys become a per-process token when the broker is on and the box has its own network (the bridge to the broker). */
diff --cc server/bot-box/plan.ts
index d72cd1e412,d073ba8e11..03df446dba
--- a/server/bot-box/plan.ts
+++ b/server/bot-box/plan.ts
@@@ -13,11 -12,10 +12,12 @@@
// 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.
+// routes of this server). Nothing else on the server's loopback is reachable. A box that waits for a sign-in callback
+// also dials out to one more socket, through which the server reaches the box's own loopback, never the other way.
+ import { statSync } from "node:fs";
import { isAbsolute, join, relative, resolve, sep } from "node:path";
export type BoxNet = "isolated" | "shared";