Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(browser): keep the local-sites switch off on shared company workspaces
AdityaUmale092f63cd6931
diff --git a/docs/browser-packaging.md b/docs/browser-packaging.mdindex 446f329692..5d592b2f5c 100644--- a/docs/browser-packaging.md+++ b/docs/browser-packaging.md@@ -139,10 +139,11 @@ link-local addresses stay closed whatever it lists, and MausBot Cloud ignoresit.Settings > Computer > "Open sites on this server" (`browserEngine.egress.localNetwork: true`, off by default and-shown only to the server's owner or an admin) opens this server's own sites and its local network without listing+shown only to the server's owner or an admin; not on a shared company workspace, whose network is the operator's) opens this server's own sites and its local network without listingthem. OpenMausBot's own ports, metadata and link-local addresses stay closed, also through a private address such asa Docker host's gateway, and a public name that resolves to loopback is still refused. It applies to new connections;-a page already open keeps the ones it has until it closes them. Every refused connection shows up in the bot's next browser result:+a page already open keeps the ones it has until it closes them. Refused connections show up in the bot's next browser result:+the first three by name and the rest as a count (up to 20 per result, each destination and reason once):`The page tried to reach "127.0.0.1:8799" (blocked: OpenMausBot's own service)`.`agent_browser_read` reads the page open in the browser. Given an address,diff --git a/server/config.ts b/server/config.tsindex bb91671eab..34f1cbf1cd 100644--- a/server/config.ts+++ b/server/config.ts@@ -953,9 +953,7 @@ export function saveConfig(const current = jsonObjectSchema.safeParse(disk[key]);const merged: JsonObject = current.success ? { ...current.data } : {};if (key === "threads" && !current.success) merged.maxConcurrentPerBot = DEFAULT_MAX_CONCURRENT_BOT_THREADS;- // A partial egress patch (the owner's local-sites switch) keeps the rest of the stored egress, such as the allow-list.- const egress = key === "browserEngine" && checkedPatch.browserEngine?.egress ? { ...jsonObjectSchema.safeParse(merged.egress).data, ...checkedPatch.browserEngine.egress } : null;- Object.assign(merged, section, egress ? { egress } : {});+ Object.assign(merged, section, key === "browserEngine" && checkedPatch.browserEngine?.egress ? { egress: { ...jsonObjectSchema.safeParse(merged.egress).data, ...checkedPatch.browserEngine.egress } } : {}); // a partial egress patch keeps the stored allow-listfor (const [sectionKey, sectionValue] of Object.entries(section as Record<string, unknown>)) {if (sectionValue === null) delete merged[sectionKey];}diff --git a/server/host/browser.test.ts b/server/host/browser.test.tsindex 74832277e1..329d6a1f3f 100644--- a/server/host/browser.test.ts+++ b/server/host/browser.test.ts@@ -43,8 +43,8 @@ afterEach(async () => { await Promise.all(hosts.splice(0).map((host) => host.broconst turn = { threadId: "thread-1", generation: "gen-1" };-function setup(engine: "chrome" | "agent-browser" | undefined, { cloudHome = false, device, lendRefusal, holder, audienceOf, bots: botIds = ["scout"], browserBox, lentChrome, turnResources }: {- cloudHome?: boolean; device?: BrowserHostDeps["device"]; lendRefusal?: BrowserHostDeps["lendRefusal"]; holder?: (resource: string) => TurnOwner | undefined;+function setup(engine: "chrome" | "agent-browser" | undefined, { cloudHome = false, server = false, hosted = false, device, lendRefusal, holder, audienceOf, bots: botIds = ["scout"], browserBox, lentChrome, turnResources }: {+ cloudHome?: boolean; server?: boolean; hosted?: boolean; device?: BrowserHostDeps["device"]; lendRefusal?: BrowserHostDeps["lendRefusal"]; holder?: (resource: string) => TurnOwner | undefined;audienceOf?: BrowserHostDeps["audienceOf"]; bots?: string[]; browserBox?: BrowserHostDeps["browserBox"];lentChrome?: BrowserHostDeps["lentChrome"]; turnResources?: BrowserHostDeps["turnResources"];} = {}) {@@ -64,8 +64,9 @@ function setup(engine: "chrome" | "agent-browser" | undefined, { cloudHome = falturnResources: turnResources ?? { free: () => true, holder: holder ?? (() => undefined), onClaim: () => () => {} },activeInternalGenerationByThread: new Map([[turn.threadId, turn.generation]]),mintInternalCapability: (capability) => { minted.push(capability); return "capability-token"; },- DESKTOP_MANAGED: !cloudHome,+ DESKTOP_MANAGED: !cloudHome && !server,CLOUD_HOME: cloudHome ? { machineId: "m-1" } : null,+ HOSTED_WORKSPACE: hosted,PORT: 4100,device,lendRefusal,@@ -136,6 +137,17 @@ describe("the bots' browser host with browserEngine.engine set to chrome", () =>expect(host.engineSummary({ kind: "unavailable", reason: "agent-browser is not installed", myChrome: true })).toEqual({ kind: "unavailable", reason: "agent-browser is not installed", myChrome: true, engine: "agent-browser" });});+ it("offers the owner's local-sites switch on a self-hosted server, but never on a shared company workspace", () => {+ const unavailable = { kind: "unavailable" as const, reason: "agent-browser is not installed", myChrome: false };+ for (const hosted of [false, true]) {+ const { cfg, host } = setup("agent-browser", { server: true, hosted });+ cfg.browserEngine = { engine: "agent-browser", egress: { localNetwork: true } };+ expect(host.engineSummary(unavailable).serverSites).toBe(hosted ? undefined : true);+ expect(browserEgress.rules().localNetwork).toBe(!hosted);+ }+ expect(setup("agent-browser").host.engineSummary(unavailable).serverSites).toBeUndefined();+ });+it("forgets the new engine's sessions when the engine is switched back", async () => {const { cfg, host } = setup("chrome");const browser = await host.browserIntegration("scout", undefined, turn);diff --git a/server/host/browser.ts b/server/host/browser.tsindex 7bca64f1df..f152eada27 100644--- a/server/host/browser.ts+++ b/server/host/browser.ts@@ -62,6 +62,8 @@ export interface BrowserHostDeps {}): string;DESKTOP_MANAGED: boolean;CLOUD_HOME: unknown;+ /** A shared company workspace: the server's network is the operator's, so the owner's local-sites switch stays off. */+ HOSTED_WORKSPACE?: boolean;PORT: number;/** A Cloud home's way out through the person's own lent computer. */device?: EgressSetup["device"];@@ -204,7 +206,10 @@ export function createBrowserHost(deps: BrowserHostDeps) {const browserAudience = (threadId: string | undefined): Audience => (threadId && deps.audienceOf ? deps.audienceOf(threadId) : "team");const device = deps.device && lentDevice(deps.device, (session) => turnResources.holder(`browser:${session}`), mayLend);const egressHost = DESKTOP_MANAGED ? "desktop" : CLOUD_HOME ? "cloud" : "server";- browserEgress.configure({ host: egressHost, config: () => cfg.browserEngine?.egress, ...(device ? { device } : {}) });+ // Self-hosted servers only: the owner's switch for this server's own sites and its local network.+ const sitesSwitch = egressHost === "server" && !deps.HOSTED_WORKSPACE;+ const egressConfig = () => (sitesSwitch || !cfg.browserEngine?.egress ? cfg.browserEngine?.egress : { ...cfg.browserEngine.egress, localNetwork: false });+ browserEgress.configure({ host: egressHost, config: egressConfig, ...(device ? { device } : {}) });/** A live bot's, profile's or temporary browser of this data dir, for any audience. */const belongs = (session: string) => isTemporaryBrowserSession(session) || audiences.variants().some((suffix) =>store.bots.some((bot) => browserSessionId(bot.id + suffix, "") === session)@@ -533,8 +538,7 @@ export function createBrowserHost(deps: BrowserHostDeps) {}/** What Settings shows of the engine that runs bots' browsers here; My Chrome stays on agent-browser. */function engineSummary<T extends { myChrome: boolean }>(agentBrowser: T): (T | (ReturnType<ChromeEngine["summary"]> & { myChrome: boolean })) & { engine: BrowserEngineKind; serverSites?: boolean } {- // Self-hosted servers only: the owner's switch for this server's own sites and its local network.- const serverSites = egressHost === "server" ? { serverSites: cfg.browserEngine?.egress?.localNetwork === true } : {};+ const serverSites = sitesSwitch ? { serverSites: cfg.browserEngine?.egress?.localNetwork === true } : {};if (browserEngineKind(cfg) !== "chrome") return { ...agentBrowser, ...serverSites, engine: "agent-browser" };return { ...chromeEngine.summary(), myChrome: agentBrowser.myChrome, ...lentChromeSummary(), ...serverSites, engine: "chrome" };}diff --git a/server/index.ts b/server/index.tsindex 1ccf9b0d5a..4d66412cbb 100644--- a/server/index.ts+++ b/server/index.ts@@ -2428,7 +2428,7 @@ const {browserRuntime, browserLive, usedBrowserSessions, browserSweep, temporaryBrowserSessions,currentBrowserSession, forgetTemporaryBrowser, myChromeAvailable, usesMyChrome, lentChromeSummary, browserSessionSpec, browserIntegration,browserReady, currentBrowserSpec, loginInput, browserSystemPrompt, closeBrowser, browserEngineSwitched, eraseDeletedBrowser, engineSummary, browserSessionsOf, signedInSitesTarget, uploadPaths, eraseAudienceBrowsers,-} = createBrowserHost({ cfg, store: () => store, turnResources, activeInternalGenerationByThread, mintInternalCapability, DESKTOP_MANAGED, CLOUD_HOME, PORT, engineMemory, audienceOf: teamHost.browserAudience, ...(CLOUD_TEAM ? { browserBox: (fd: number, ro: readonly string[]) => botBox.browserBox(fd, ro) } : {}), lendRefusal: (turn) => cloudLendingRefusal({ botId: store.botByThread(turn.threadId)?.id ?? "", threadId: turn.threadId, generation: turn.generation }), device: () => deviceLinks.route(CLOUD_HOME_LENDER) ?? sharedComputers.internetAway(CLOUD_HOME_LENDER) ?? { unshared: true as const }, lentChrome: CLOUD_PERSONAL ? { route: () => deviceLinks.chromeRoute(CLOUD_HOME_LENDER), lender: () => sharedComputers.chromeLender(CLOUD_HOME_LENDER) } : undefined });+} = createBrowserHost({ cfg, store: () => store, turnResources, activeInternalGenerationByThread, mintInternalCapability, DESKTOP_MANAGED, CLOUD_HOME, HOSTED_WORKSPACE, PORT, engineMemory, audienceOf: teamHost.browserAudience, ...(CLOUD_TEAM ? { browserBox: (fd: number, ro: readonly string[]) => botBox.browserBox(fd, ro) } : {}), lendRefusal: (turn) => cloudLendingRefusal({ botId: store.botByThread(turn.threadId)?.id ?? "", threadId: turn.threadId, generation: turn.generation }), device: () => deviceLinks.route(CLOUD_HOME_LENDER) ?? sharedComputers.internetAway(CLOUD_HOME_LENDER) ?? { unshared: true as const }, lentChrome: CLOUD_PERSONAL ? { route: () => deviceLinks.chromeRoute(CLOUD_HOME_LENDER), lender: () => sharedComputers.chromeLender(CLOUD_HOME_LENDER) } : undefined });const dataSheets = new DataSheetRegistry({broadcast: (frame) => broadcast({ ...frame }),