Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

fix: Codex TUI agents bypass sandbox so headless gh/network works

Adam Eivy1d1cace1b8c7
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.md
index 8b8fd9c810..81b70bfa85 100644
--- a/.changelog/NEXT.md
+++ b/.changelog/NEXT.md
@@ -2,6 +2,7 @@
## Fixed
+- **Codex TUI CoS agents no longer get stuck in the sandbox.** The shipped Codex TUI provider pinned `--ask-for-approval never`, which silences approval prompts but leaves Codex's *sandbox* at its default (`workspace-write`) — so headless agents couldn't reach the network (`gh`/`npm`/`git fetch` failed) and could still hit surprise escalation prompts mid-run. Because an explicit `--ask-for-approval` flag also suppressed the auto-injected full-bypass, the shipped default actively defeated the headless posture the CLI codex path already uses. The default now ships `--dangerously-bypass-approvals-and-sandbox` (approvals off + sandbox off + network on), and migration 121 rewrites existing installs whose args still match the old default — custom Codex flags are left untouched.
- AI provider context-window planning is now model-aware: known Claude model windows are used after explicit provider overrides and before local `num_ctx`, and the provider settings UI shows/edits the planning window so mixed-model providers no longer collapse to one blunt 128K budget.
- **AI fixers can no longer take down the whole server with `pm2 kill`.** PortOS runs every managed app under one shared pm2 daemon, so `pm2 kill` / `pm2 delete all` stops *everything* — including PortOS itself. A "Fix with AI" / autofixer agent (which runs its CLI fully unrestricted) could be talked into running one while trying to "restart the app." Three layers now block this: (1) the shell-command allowlist (`validateCommand`) rejects `pm2 kill`/`startup`/`unstartup` and any `pm2 <verb> all` for the manual command runner and autonomous jobs; (2) spawned AI agents (CoS tasks, the autofixer app) get a guarded `pm2` shim prepended to their PATH that intercepts those same destructive subcommands before they reach the real pm2 — a hard guard that holds even under `--dangerously-skip-permissions`; (3) every agent prompt now states the shared-daemon rule and to only `pm2 restart <its-own-process>`. Scoped commands (`pm2 restart my-app`, `pm2 logs my-app`, `pm2 list`) still work.
diff --git a/data.reference/providers.json b/data.reference/providers.json
index 855c2b7638..4028c8b66d 100644
--- a/data.reference/providers.json
+++ b/data.reference/providers.json
@@ -70,7 +70,7 @@
"name": "Codex TUI",
"type": "tui",
"command": "codex",
- "args": ["--ask-for-approval", "never"],
+ "args": ["--dangerously-bypass-approvals-and-sandbox"],
"models": ["codex-configured-default"],
"defaultModel": "codex-configured-default",
"lightModel": "codex-configured-default",
diff --git a/scripts/migrations/121-codex-tui-bypass-sandbox.js b/scripts/migrations/121-codex-tui-bypass-sandbox.js
new file mode 100644
index 0000000000..1de4ed0028
--- /dev/null
+++ b/scripts/migrations/121-codex-tui-bypass-sandbox.js
@@ -0,0 +1,81 @@
+/**
+ * Fix the Codex TUI provider's headless posture so CoS agents stop hitting
+ * sandbox/approval walls (e.g. `gh` failing to reach the network, surprise
+ * permission prompts mid-run).
+ *
+ * The prior shipped default pinned `args: ["--ask-for-approval", "never"]`.
+ * That silences the approval prompts but leaves Codex's *sandbox* at its
+ * default (`workspace-write`), which blocks network access and can still force
+ * escalation prompts. Worse, because `applyCommandDefaults()` treats an
+ * explicit `--ask-for-approval` as "the user pinned a policy," it suppressed
+ * the auto-injected `--dangerously-bypass-approvals-and-sandbox` that's meant
+ * to give headless agents the full-yolo posture — so the shipped default
+ * actively defeated the bypass mechanism. The CLI codex path already runs
+ * `exec --dangerously-bypass-approvals-and-sandbox`; the TUI path should match.
+ *
+ * `setup-data.js` merges *missing* provider entries but never updates existing
+ * ones, so deployed installs keep the broken args until a migration rewrites
+ * them.
+ *
+ * Conservative: only rewrite when `args` STILL EXACTLY matches the old shipped
+ * default `["--ask-for-approval", "never"]`. A user who curated their own Codex
+ * flags (any other combination) is left alone.
+ */
+
+import { readFile, writeFile } from 'fs/promises';
+import { join } from 'path';
+
+const PROVIDERS_REL_PATH = 'data/providers.json';
+
+const TARGET_ID = 'codex-tui';
+const OLD_ARGS = ['--ask-for-approval', 'never'];
+const NEW_ARGS = ['--dangerously-bypass-approvals-and-sandbox'];
+
+// Order-sensitive equality — a reordered/extended arg list counts as
+// customization and is skipped.
+const sameArray = (a, b) => {
+ if (!Array.isArray(a) || !Array.isArray(b) || a.length !== b.length) return false;
+ return a.every((v, i) => v === b[i]);
+};
+
+export default {
+ async up({ rootDir }) {
+ const providersPath = join(rootDir, PROVIDERS_REL_PATH);
+ const raw = await readFile(providersPath, 'utf-8').catch((err) => {
+ if (err.code === 'ENOENT') return null;
+ throw err;
+ });
+ if (raw == null) {
+ console.log(`📄 ${PROVIDERS_REL_PATH} not present — skipping (fresh install seeds from data.reference with the new args)`);
+ return;
+ }
+
+ let config;
+ try {
+ config = JSON.parse(raw);
+ } catch (err) {
+ console.log(`⚠️ ${PROVIDERS_REL_PATH}: invalid JSON, skipping (${err.message})`);
+ return;
+ }
+
+ const provider = config?.providers?.[TARGET_ID];
+ if (!provider) {
+ console.log(`✅ ${PROVIDERS_REL_PATH}: no ${TARGET_ID} provider — nothing to do`);
+ return;
+ }
+
+ if (sameArray(provider.args, NEW_ARGS)) {
+ console.log(`✅ ${PROVIDERS_REL_PATH}: ${TARGET_ID} already on the bypass posture — no change`);
+ return;
+ }
+
+ if (!sameArray(provider.args, OLD_ARGS)) {
+ console.log(`✅ ${PROVIDERS_REL_PATH}: ${TARGET_ID} args customized (${JSON.stringify(provider.args)}) — leaving alone`);
+ return;
+ }
+
+ provider.args = [...NEW_ARGS];
+ await writeFile(providersPath, `${JSON.stringify(config, null, 2)}\n`);
+ console.log(`📝 ${PROVIDERS_REL_PATH}: ${TARGET_ID} args → --dangerously-bypass-approvals-and-sandbox (headless network + no approval walls)`);
+ },
+};
diff --git a/scripts/migrations/121-codex-tui-bypass-sandbox.test.js b/scripts/migrations/121-codex-tui-bypass-sandbox.test.js
new file mode 100644
index 0000000000..83e926e528
--- /dev/null
+++ b/scripts/migrations/121-codex-tui-bypass-sandbox.test.js
@@ -0,0 +1,125 @@
+/**
+ * Test for migration 121 — flip the Codex TUI provider from the partial
+ * `--ask-for-approval never` posture (sandbox still on, network blocked) to the
+ * full `--dangerously-bypass-approvals-and-sandbox` headless posture. Picked up
+ * by server/vitest.config.js's `../scripts/**\/*.test.js` glob.
+ */
+import { describe, it, expect, beforeEach, afterEach } from 'vitest';
+import { mkdtempSync, rmSync, writeFileSync, readFileSync, mkdirSync, existsSync } from 'fs';
+import { tmpdir } from 'os';
+import { join } from 'path';
+
+import migration from './121-codex-tui-bypass-sandbox.js';
+
+const writeJson = (path, value) => writeFileSync(path, JSON.stringify(value, null, 2) + '\n');
+const readJson = (path) => JSON.parse(readFileSync(path, 'utf-8'));
+
+const OLD_ARGS = ['--ask-for-approval', 'never'];
+const NEW_ARGS = ['--dangerously-bypass-approvals-and-sandbox'];
+
+const codexTui = (overrides = {}) => ({
+ id: 'codex-tui',
+ name: 'Codex TUI',
+ type: 'tui',
+ command: 'codex',
+ args: [...OLD_ARGS],
+ enabled: false,
+ ...overrides,
+});
+
+describe('migration 121 — Codex TUI bypass sandbox', () => {
+ let rootDir;
+ let providersPath;
+
+ beforeEach(() => {
+ rootDir = mkdtempSync(join(tmpdir(), 'migration-121-'));
+ mkdirSync(join(rootDir, 'data'), { recursive: true });
+ providersPath = join(rootDir, 'data/providers.json');
+ });
+
+ afterEach(() => {
+ rmSync(rootDir, { recursive: true, force: true });
+ });
+
+ it('rewrites the old `--ask-for-approval never` args to the full bypass flag', async () => {
+ writeJson(providersPath, { providers: { 'codex-tui': codexTui() } });
+
+ await migration.up({ rootDir });
+
+ const after = readJson(providersPath).providers['codex-tui'];
+ expect(after.args).toEqual(NEW_ARGS);
+ // unrelated fields preserved
+ expect(after.command).toBe('codex');
+ expect(after.enabled).toBe(false);
+ });
+
+ it('is a no-op when args are already the bypass flag', async () => {
+ writeJson(providersPath, { providers: { 'codex-tui': codexTui({ args: [...NEW_ARGS] }) } });
+ const before = readFileSync(providersPath, 'utf-8');
+
+ await migration.up({ rootDir });
+
+ expect(readFileSync(providersPath, 'utf-8')).toBe(before);
+ });
+
+ it('leaves customized args alone (user pinned their own sandbox)', async () => {
+ const customized = codexTui({ args: ['--ask-for-approval', 'never', '--sandbox', 'workspace-write'] });
+ writeJson(providersPath, { providers: { 'codex-tui': customized } });
+ const before = readFileSync(providersPath, 'utf-8');
+
+ await migration.up({ rootDir });
+
+ expect(readFileSync(providersPath, 'utf-8')).toBe(before);
+ });
+
+ it('treats reordered args as customization (skip)', async () => {
+ const reordered = codexTui({ args: ['never', '--ask-for-approval'] });
+ writeJson(providersPath, { providers: { 'codex-tui': reordered } });
+ const before = readFileSync(providersPath, 'utf-8');
+
+ await migration.up({ rootDir });
+
+ expect(readFileSync(providersPath, 'utf-8')).toBe(before);
+ });
+
+ it('does not touch other providers', async () => {
+ writeJson(providersPath, {
+ providers: {
+ 'codex-tui': codexTui(),
+ 'codex': { id: 'codex', type: 'cli', command: 'codex', args: [] },
+ 'claude-code-tui': { id: 'claude-code-tui', type: 'tui', args: ['-p', '-'] },
+ },
+ });
+
+ await migration.up({ rootDir });
+
+ const out = readJson(providersPath).providers;
+ expect(out['codex-tui'].args).toEqual(NEW_ARGS);
+ expect(out['codex'].args).toEqual([]);
+ expect(out['claude-code-tui'].args).toEqual(['-p', '-']);
+ });
+
+ it('is a no-op when codex-tui provider is absent', async () => {
+ writeJson(providersPath, { providers: { 'codex': { id: 'codex', args: [] } } });
+ const before = readFileSync(providersPath, 'utf-8');
+
+ await migration.up({ rootDir });
+
+ expect(readFileSync(providersPath, 'utf-8')).toBe(before);
+ });
+
+ it('is a no-op when data/providers.json does not exist (fresh install)', async () => {
+ await migration.up({ rootDir });
+
+ expect(existsSync(providersPath)).toBe(false);
+ });
+
+ it('does not modify the file on invalid JSON (logs a warning and skips)', async () => {
+ writeFileSync(providersPath, '{ not valid json');
+ const before = readFileSync(providersPath, 'utf-8');
+
+ await migration.up({ rootDir });
+
+ expect(readFileSync(providersPath, 'utf-8')).toBe(before);
+ });
+});
diff --git a/server/lib/aiToolkit/defaults/providers.sample.json b/server/lib/aiToolkit/defaults/providers.sample.json
index b0ecc4e8fb..571ddcd3d2 100644
--- a/server/lib/aiToolkit/defaults/providers.sample.json
+++ b/server/lib/aiToolkit/defaults/providers.sample.json
@@ -60,7 +60,7 @@
"name": "Codex TUI",
"type": "tui",
"command": "codex",
- "args": ["--ask-for-approval", "never"],
+ "args": ["--dangerously-bypass-approvals-and-sandbox"],
"models": ["codex-configured-default"],
"defaultModel": "codex-configured-default",
"lightModel": "codex-configured-default",