Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Local VM: expose Docker host gateway on Linux
skygunnerbc9ccf459ec5
diff --git a/apps/docs/content/docs/computers/local-vm.mdx b/apps/docs/content/docs/computers/local-vm.mdxindex 31d1fd6ef8..8b76ac0d5e 100644--- a/apps/docs/content/docs/computers/local-vm.mdx+++ b/apps/docs/content/docs/computers/local-vm.mdx@@ -69,6 +69,20 @@ Desktops made before this change keep their old capabilities until they are recrOn Linux with Docker Engine, the desktop's `cua` account takes the user ID and group ID of the account running MausBot, so files the bot writes in its workspace belong to you on the host. The first start of a new desktop takes longer while it does this. If MausBot runs as root, the workspace is handed to user ID 1000 instead, which is the desktop's own `cua` account. Rootless Podman maps the IDs itself. Rootless Docker is not covered: its user IDs inside containers do not match the host's.+## Reach a service on the Linux Docker host++New Local VMs on Linux with Docker Engine 20.10 or later can use `host.docker.internal` to reach a service on the Docker host. Docker resolves the name to its host gateway. To find the default bridge's gateway and subnet, run `docker network inspect bridge` on the host and look under **IPAM → Config**. For a desktop created before the alias was added, use that gateway address directly.++Bind the service, or a dedicated listener for it, to the bridge gateway address. Inside the Local VM, `127.0.0.1` is the desktop container's own loopback. If you use UFW, allow inbound traffic on the bridge interface to the service's specific address and port. For example, for a service that listens on `172.17.0.1:8080` and a Local VM at `172.17.0.2` on `docker0`, the rule is:++```sh+sudo ufw allow in on docker0 proto tcp from 172.17.0.2 to 172.17.0.1 port 8080+```++Use your actual interface, addresses and port. If the Local VM's address changes when it is recreated, update the rule. From the VM, check an endpoint the service provides, such as `curl --fail --max-time 5 http://host.docker.internal:8080/health`.++The `environment` map on an engine instance in `config.json` applies to the engine process. Commands run through the Local VM's shell have the desktop container's environment. Use the service's VM address in the bot's instructions or in an integration configured inside the VM.+## PersistenceThe bot's workspace and browser profile live in a durable mounted directory. Recreating the desktop can repair stale runtime state without deleting the durable workspace.diff --git a/server/container-computer.test.ts b/server/container-computer.test.tsindex 4dd259f187..bab2e48fa1 100644--- a/server/container-computer.test.ts+++ b/server/container-computer.test.ts@@ -1297,6 +1297,21 @@ describe("setupCommands", () => {expect(command).toContain("VNC_PW=CHANGE_ME");});+ it("maps the Docker host gateway for new Linux desktops", () => {+ const mapping = "--add-host host.docker.internal:host-gateway";+ expect(setupCommands("docker", "linux").run).toContain(mapping);+ const target = perBotLocalVmTarget("bot-a");+ const args = containerRunArgs("docker", "secret", target, {+ platform: "linux", resources: { memoryGb: 4, cpus: 2 }, hostUser: null,+ });+ expect(args.slice(0, args.indexOf(IMAGE)).join(" ")).toContain(mapping);+ expect(args).toContain("127.0.0.1::6901");+ expect(args).not.toContain("--network");+ for (const [runtime, platform] of [["docker", "darwin"], ["docker", "win32"], ["podman", "linux"], ["container", "darwin"]] as const) {+ expect(setupCommands(runtime, platform).run).not.toContain(mapping);+ }+ });+it("offers a start command for a stopped compatible desktop", () => {expect(setupCommands("docker", "linux").start).toBe(`docker start ${CONTAINER}`);});diff --git a/server/container-computer.ts b/server/container-computer.tsindex b72081f431..4b7b04b16c 100644--- a/server/container-computer.ts+++ b/server/container-computer.ts@@ -786,9 +786,9 @@ export function containerRunArgs(// Apple container already places each Linux container in a lightweight VM.common.push(...resourceArgs(desktop.resources, { swap: false }), ...desktopCapArgs(runtime), "--shm-size", "512m");} else {+ if (runtime === "docker" && desktop.platform === "linux") common.push("--add-host", "host.docker.internal:host-gateway");common.push(- "--hostname",- target.containerName,+ "--hostname", target.containerName,...resourceArgs(desktop.resources, { swap: true }),"--pids-limit", String(PIDS_LIMIT),// Pinned: a daemon with host-mode IPC/cgroup defaults would create a container the hardening check then rejects.