Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
fix(codex): explain Linux user-namespace sandbox UID mapping for SSH errors (#7080)
jonathanwxh-cellaf9c7fd62387
diff --git a/docs/approval-levels.md b/docs/approval-levels.mdindex 6e5860af47..7de198f2b0 100644--- a/docs/approval-levels.md+++ b/docs/approval-levels.md@@ -386,6 +386,14 @@ choose Ask. Switching models within Antigravity keeps the selected level.Native modes require a CLI version that supports them; OpenMausBot does notsilently substitute unrestricted access when a mode is rejected.+On Linux, Codex's sandboxed modes (`Ask`, `Auto`, and `Custom` when configured+with `workspace-write` or `read-only`) run shell commands in a user namespace+where root-owned files (such as `/etc/ssh/ssh_config.d/*`) appear owned by+`nobody` (uid 65534) and network access may be restricted. OpenSSH can reject+those config files with `Bad owner or permissions on /etc/ssh/...`; use an+approved escalation or `Full access` (`danger-full-access`) for `ssh` and+`git`-over-SSH commands.+### Read-only integration toolsOpenMausBot's built-in agents MCP server describes its scoped reads withdiff --git a/server/drivers/codex-instructions.test.ts b/server/drivers/codex-instructions.test.tsindex cfa0283462..5fef12a163 100644--- a/server/drivers/codex-instructions.test.ts+++ b/server/drivers/codex-instructions.test.ts@@ -3,7 +3,8 @@ import { readFileSync, writeFileSync } from "node:fs";import { join } from "node:path";import { describe, expect, it, vi } from "vitest";import { DATA_DIR } from "../config.ts";-import { codexDeveloperInstructions, syncCodexInstructions } from "./codex-instructions.ts";+import { CODEX_LINUX_SANDBOX_NOTE, codexDeveloperInstructions, codexSandboxNote, syncCodexInstructions } from "./codex-instructions.ts";+import { customApprovalParams, namedApprovalParams } from "./codex-approval-config.ts";const receiptPath = (key: string, nativeThreadId: string) =>join(DATA_DIR, "codex-instructions", `${createHash("sha256").update(JSON.stringify([key, nativeThreadId])).digest("hex")}.sha256`);@@ -17,6 +18,40 @@ describe("Codex effective developer instructions", () => {expect(codexDeveloperInstructions({ developer_instructions: null }, "")).toBe("");});+ it("appends a sandbox note after bot instructions and before native rules without altering 2-arg output", () => {+ const config = { developer_instructions: "Native rules." };+ expect(codexDeveloperInstructions(config, "Bot rules.", CODEX_LINUX_SANDBOX_NOTE)).toBe(+ `Bot rules.\n\n${CODEX_LINUX_SANDBOX_NOTE}\n\nNative rules.`,+ );+ expect(codexDeveloperInstructions(config, "", CODEX_LINUX_SANDBOX_NOTE)).toBe(+ `No OpenMausBot bot-specific instructions remain.\n\n${CODEX_LINUX_SANDBOX_NOTE}\n\nNative rules.`,+ );+ expect(codexDeveloperInstructions({}, "", CODEX_LINUX_SANDBOX_NOTE)).toBe(+ `No OpenMausBot bot-specific instructions remain.\n\n${CODEX_LINUX_SANDBOX_NOTE}`,+ );+ expect(codexDeveloperInstructions({}, "Bot rules.", "")).toBe("Bot rules.");+ });++ it("explains Linux sandbox UID mapping only for sandboxed Linux turns", () => {+ for (const mode of ["ask", "auto", "edits"] as const) {+ const note = codexSandboxNote(namedApprovalParams(mode), "linux");+ expect(note).toBe(CODEX_LINUX_SANDBOX_NOTE);+ expect(note).toContain("/etc/ssh/");+ expect(note).toContain("nobody");+ }+ expect(codexSandboxNote(namedApprovalParams("full"), "linux")).toBe("");+ expect(codexSandboxNote(namedApprovalParams("ask"), "darwin")).toBe("");+ expect(codexSandboxNote(namedApprovalParams("auto"), "win32")).toBe("");++ expect(codexSandboxNote(customApprovalParams({ sandbox_mode: "workspace-write" }), "linux")).toBe(CODEX_LINUX_SANDBOX_NOTE);+ expect(codexSandboxNote(customApprovalParams({ sandbox_mode: "read-only" }), "linux")).toBe(CODEX_LINUX_SANDBOX_NOTE);+ expect(codexSandboxNote(customApprovalParams({ sandbox_mode: "danger-full-access" }), "linux")).toBe("");+ // Active `permissions` profiles hide the effective sandbox from OpenMausBot, so never guess from inactive fallback config or add a stale thread.sandbox override.+ expect(codexSandboxNote(customApprovalParams({ default_permissions: "restricted", sandbox_mode: "workspace-write" }), "linux")).toBe("");+ expect(codexSandboxNote(customApprovalParams({ default_permissions: "unrestricted" }), "linux")).toBe("");+ expect(codexSandboxNote({ thread: { sandbox: "danger-full-access" }, turn: { sandboxPolicy: { type: "workspaceWrite" } } }, "linux")).toBe(CODEX_LINUX_SANDBOX_NOTE);+ });+it.each([undefined, null, [], { developer_instructions: 42 }])("rejects unknown native configuration: %j", (config) => {expect(() => codexDeveloperInstructions(config, "Bot rules.")).toThrow("cannot safely update bot instructions");});diff --git a/server/drivers/codex-instructions.ts b/server/drivers/codex-instructions.tsindex ade5f867c9..b78ebbbfbe 100644--- a/server/drivers/codex-instructions.ts+++ b/server/drivers/codex-instructions.ts@@ -5,6 +5,26 @@ import { mkdirSync, readFileSync } from "node:fs";import { join } from "node:path";import { DATA_DIR } from "../config.ts";import { writeFileAtomic } from "../atomic.ts";+import type { CodexApprovalParams } from "./codex-approval-config.ts";++export const CODEX_LINUX_SANDBOX_NOTE =+ "Shell commands in this turn run inside Codex's Linux user-namespace sandbox, where root-owned files (such as /etc/ssh/ssh_config.d/*) appear owned by nobody (uid 65534) and network access may be restricted. OpenSSH errors like \"Bad owner or permissions on /etc/ssh/...\" are caused by this sandbox rather than host file permissions; ssh and git-over-SSH require an approved escalation outside the sandbox.";++/** Explains Linux user-namespace uid mapping when Codex turns run inside a sandbox. */+export function codexSandboxNote(+ params: Pick<CodexApprovalParams, "thread" | "turn">,+ platform: NodeJS.Platform = process.platform,+): string {+ if (platform !== "linux") return "";+ const sandboxPolicy = (params.turn.sandboxPolicy as { type?: unknown } | undefined)?.type;+ if (typeof sandboxPolicy === "string") {+ return sandboxPolicy === "dangerFullAccess" ? "" : CODEX_LINUX_SANDBOX_NOTE;+ }+ if (typeof params.thread.permissions === "string") return "";+ const threadSandbox = params.thread.sandbox;+ if (typeof threadSandbox !== "string" || threadSandbox === "danger-full-access") return "";+ return CODEX_LINUX_SANDBOX_NOTE;+}const digest = (value: string) => createHash("sha256").update(value).digest("hex");@@ -35,7 +55,7 @@ function parseReceipt(raw: string | undefined): CodexInstructionReceipt | null {}/** Preserve native configured rules when overriding Codex's developer slot. */-export function codexDeveloperInstructions(config: unknown, botInstructions: string): string {+export function codexDeveloperInstructions(config: unknown, botInstructions: string, sandboxNote = ""): string {if (!config || typeof config !== "object" || Array.isArray(config)) {throw new Error("Codex returned no effective configuration; cannot safely update bot instructions.");}@@ -44,8 +64,9 @@ export function codexDeveloperInstructions(config: unknown, botInstructions: strthrow new Error("Codex returned invalid developer instructions; cannot safely update bot instructions.");}// Native rules go last, keeping their precedence over the bot's.- return configured- ? `${botInstructions || "No OpenMausBot bot-specific instructions remain."}\n\n${configured}`+ const trailing = [sandboxNote, configured].filter((part): part is string => Boolean(part)).join("\n\n");+ return trailing+ ? `${botInstructions || "No OpenMausBot bot-specific instructions remain."}\n\n${trailing}`: botInstructions;}diff --git a/server/drivers/codex.test.ts b/server/drivers/codex.test.tsindex 023bfee31e..908151c556 100644--- a/server/drivers/codex.test.ts+++ b/server/drivers/codex.test.ts@@ -18,6 +18,7 @@ import { recordEvents, type EventRecorder } from "../testing/events.ts";import { publishedMessages, replyProblems } from "../harness/text-items.testkit.ts";import { caseTokens, LIVE_REPLY_CASES, liveReplyScripts } from "../testing/live-reply-cases.ts";import { CodexDriver, codexNativeIncomingLogMessage, codexUpdateCommand } from "./codex.ts";+import { CODEX_LINUX_SANDBOX_NOTE } from "./codex-instructions.ts";import { codexCliOverrides } from "./codex-process.ts";import { codexReleaseUpdate } from "./codex-update.ts";import { parseToml } from "../toml-lite.ts";@@ -39,6 +40,8 @@ import { boxEnvironment } from "../bot-box/env.ts";import { autoVerdict } from "../auto-approve.ts";import { formatQuestionAnswers } from "../../shared/ask-question.ts";+const codexSandboxSuffix = process.platform === "linux" ? `\n\n${CODEX_LINUX_SANDBOX_NOTE}` : "";+vi.mock("./codex-release.ts", async (importOriginal) => ({...await importOriginal<typeof import("./codex-release.ts")>(),readLatestCodexRelease: async () => "0.156.1",@@ -811,7 +814,7 @@ process.stdout.write(JSON.stringify({jsonrpc:'2.0',id:m.id,result})+'\\n');});`)const turnStart = seen.calls.at(-1);expect(turnStart.params.input[0].text).toBe("list files");const threadStart = seen.calls.find((c: { method: string }) => c.method === "thread/start");- expect(threadStart.params).toMatchObject({ model: "gpt-5.6-sol", modelProvider: "openai", developerInstructions: "You are Testy." });+ expect(threadStart.params).toMatchObject({ model: "gpt-5.6-sol", modelProvider: "openai", developerInstructions: `You are Testy.${codexSandboxSuffix}` });});it("keeps the developer slot stable and delivers volatile context in-turn", async () => {@@ -839,7 +842,7 @@ process.stdout.write(JSON.stringify({jsonrpc:'2.0',id:m.id,result})+'\\n');});`)const third = await send("split-3.json", "third", "Memory: moved to Toronto.", "codex-thread-1");const threadStarts = first.filter((c) => c.method === "thread/start");expect(threadStarts).toHaveLength(1);- expect(threadStarts[0].params.developerInstructions).toBe("Stable rules.");+ expect(threadStarts[0].params.developerInstructions).toBe(`Stable rules.${codexSandboxSuffix}`);for (const calls of [first, second, third]) {expect(calls.some((c) => c.method === "thread/inject_items")).toBe(false);}@@ -2946,7 +2949,12 @@ process.stdout.write(JSON.stringify({jsonrpc:'2.0',id:m.id,result})+'\\n');});`)}>;const threadCalls = calls.filter((call) => ["thread/start", "thread/resume"].includes(call.method));expect(threadCalls.length).toBeGreaterThan(0);- for (const call of threadCalls) expect(call.params.developerInstructions).toBe(system ?? "");+ const expectedDeveloper = system+ ? `${system}${codexSandboxSuffix}`+ : codexSandboxSuffix+ ? `No OpenMausBot bot-specific instructions remain.${codexSandboxSuffix}`+ : "";+ for (const call of threadCalls) expect(call.params.developerInstructions).toBe(expectedDeveloper);if (index > 0) expect(threadCalls[0].method).toBe("thread/resume");const updates = calls.filter((call) => call.method === "thread/inject_items");expect(updates).toHaveLength(index === 2 || index === 3 ? 1 : 0);@@ -2973,10 +2981,11 @@ process.stdout.write(JSON.stringify({jsonrpc:'2.0',id:m.id,result})+'\\n');});`)// One app-server serves all three turns, so its calls add up: the rules are replaced once, when they change.const calls = JSON.parse(readFileSync(dump, "utf8")).calls;expect(calls.filter((call: { method: string }) => call.method === "thread/resume")).toHaveLength(0);- expect(calls.find((call: { method: string }) => call.method === "thread/start").params.developerInstructions).toBe("Bot rules.\n\nPrivate native rules.");+ const modeSuffix = approvalMode === "full" ? "" : codexSandboxSuffix;+ expect(calls.find((call: { method: string }) => call.method === "thread/start").params.developerInstructions).toBe(`Bot rules.${modeSuffix}\n\nPrivate native rules.`);const updates = calls.filter((call: { method: string }) => call.method === "thread/inject_items");expect(updates).toHaveLength(index ? 1 : 0);- if (index) expect(JSON.stringify(updates[0].params)).toContain("No OpenMausBot bot-specific instructions remain.\\n\\nPrivate native rules.");+ if (index) expect(JSON.stringify(updates[0].params)).toContain(JSON.stringify(`No OpenMausBot bot-specific instructions remain.${modeSuffix}\n\nPrivate native rules.`).slice(1, -1));expect(calls.filter((call: { method: string }) => call.method === "turn/start").at(-1).params.input).toEqual([{ type: "text", text: `message-${index}` }]);}const nativeLog = readFileSync(join(NATIVE_DIR, `${threadId}.ndjson`), "utf8");@@ -3586,7 +3595,7 @@ process.stdout.write(JSON.stringify({jsonrpc:'2.0',id:m.id,result})+'\\n');});`)expect(second.done).toMatchObject({ ok: true });expect(seen().pid).not.toBe(pid);expect(processIsAlive(pid)).toBe(false);- expect(methods("thread/resume")[0]!.params.developerInstructions).toBe("Bot rules.\n\nNew native rules.");+ expect(methods("thread/resume")[0]!.params.developerInstructions).toBe(`Bot rules.${codexSandboxSuffix}\n\nNew native rules.`);expect(second.events.filter((event) => event.type === "turn.started")).toHaveLength(1);expect(second.events.some((event) => event.type === "turn.retrying" || event.type === "runtime.error")).toBe(false);expect(closes("t-config")).toEqual([{ close: "configuration changed", contractChanged: ["config:developer_instructions"] }]);diff --git a/server/drivers/codex.ts b/server/drivers/codex.tsindex 1cfd1dbc1a..4233561c7c 100644--- a/server/drivers/codex.ts+++ b/server/drivers/codex.ts@@ -49,7 +49,7 @@ import { classifyError, computeBackoff, interruptibleDelay, RETRY_MAX_ATTEMPTS }import { appendNative } from "./native.ts";import { answersAlone, permissionLaunchCwd, shellRequest } from "./permission-command.ts";import { commandSummary, toolDetailPreview } from "../tool-summary.ts";-import { codexDeveloperInstructions, syncCodexInstructions } from "./codex-instructions.ts";+import { codexDeveloperInstructions, codexSandboxNote, syncCodexInstructions } from "./codex-instructions.ts";import { volatileContextNote, withContextNote } from "./prompt-split.ts";import type { ApprovalMode } from "../../shared/approval-mode.ts";import { CodexDeviceAuthController } from "./codex-device-auth.ts"; import { messageItem } from "../harness/text-items.ts";@@ -1236,17 +1236,11 @@ export const CodexDriver: ProviderDriver<CodexConfig> = {? turn.systemStable: null;const promptSplit = stableInstructions !== null;- const developerInstructions = codexDeveloperInstructions(- effectiveConfig,- stableInstructions ?? turn.system ?? "",- );- let approvalParams: CodexApprovalParams;- if (approvalMode === "custom") {- // Omitting these on a resumed thread would keep the previous named mode.- approvalParams = customApprovalParams(effectiveConfig);- } else {- approvalParams = namedApprovalParams(approvalMode);- }+ // Omitting these on a resumed thread would keep the previous named mode.+ let approvalParams: CodexApprovalParams = approvalMode === "custom" ? customApprovalParams(effectiveConfig) : namedApprovalParams(approvalMode);+ const instructionsFor = (params: CodexApprovalParams) => codexDeveloperInstructions(effectiveConfig, stableInstructions ?? turn.system ?? "", turn.guestConfined ? "" : codexSandboxNote(params));+ // Validate effectiveConfig upfront so invalid native rules fail before thread creation/reuse.+ instructionsFor(approvalParams);// Codex's `never` means "do not ask to escalate", not "grant every requested permission":// only Full may synthesize approvals.autoAcceptPermissions = approvalMode === "full";@@ -1262,7 +1256,7 @@ export const CodexDriver: ProviderDriver<CodexConfig> = {const resumeThread = () => request("thread/resume", {...selectionConfig,threadId: cursor,- developerInstructions,+ developerInstructions: instructionsFor(approvalParams),model: selection.model,...(selection.modelProvider ? { modelProvider: selection.modelProvider } : {}),...approvalParams.thread,@@ -1302,7 +1296,7 @@ export const CodexDriver: ProviderDriver<CodexConfig> = {if (!codexThreadId) {const startThread = () => request("thread/start", {...selectionConfig,- developerInstructions,+ developerInstructions: instructionsFor(approvalParams),cwd: turn.cwd ?? homedir(),model: selection.model,...(selection.modelProvider ? { modelProvider: selection.modelProvider } : {}),@@ -1327,7 +1321,7 @@ export const CodexDriver: ProviderDriver<CodexConfig> = {const { deliverVolatile, hadVolatile, commitVolatile } = await syncCodexInstructions(threadId,codexThreadId,- developerInstructions,+ instructionsFor(approvalParams),promptSplit ? turn.systemVolatile ?? "" : "",resumedNativeThread,request,