@commonlyai/cli 0.1.333 → 0.1.335
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
package/src/commands/agent.js
CHANGED
|
@@ -112,7 +112,7 @@ import { prepareCommitAttribution } from '../lib/commit-attribution.js';
|
|
|
112
112
|
import { detectBwrap } from '../lib/sandbox/bwrap.js';
|
|
113
113
|
import { resolvePublicSandboxMode } from '../lib/sandbox/mode.js';
|
|
114
114
|
import {
|
|
115
|
-
|
|
115
|
+
CODEX_OPTED_IN_PUBLIC_POD_MESSAGE, UNSANDBOXED_FLAG, bwrapRefusedMessage, hostSandboxRefusal, windowsSandboxMessage,
|
|
116
116
|
} from '../lib/sandbox/host-check.js';
|
|
117
117
|
import {
|
|
118
118
|
UNSANDBOXED_NOTICE, codexUnconfinedForRun, codexUnsandboxedNotice, hostReportFailureMessage, hostUnconfinedForRun,
|
|
@@ -2878,7 +2878,7 @@ export const performRun = ({
|
|
|
2878
2878
|
hostUnconfined,
|
|
2879
2879
|
optedIn: codexUnconfined,
|
|
2880
2880
|
...(detectBwrapImpl ? { detectBwrap: detectBwrapImpl } : {}),
|
|
2881
|
-
}) || (codexUnconfined ?
|
|
2881
|
+
}) || (codexUnconfined ? CODEX_OPTED_IN_PUBLIC_POD_MESSAGE : null));
|
|
2882
2882
|
if (turnRefusal && placement.readError) {
|
|
2883
2883
|
throw Object.assign(
|
|
2884
2884
|
new Error(`turn deferred, because its pods could not be read: ${placement.readError.message}`, {
|
|
@@ -5653,6 +5653,14 @@ Docs:
|
|
|
5653
5653
|
console.error(`${stamp()} [${name}] ${hostRefusal}`);
|
|
5654
5654
|
process.exit(1);
|
|
5655
5655
|
}
|
|
5656
|
+
// F444: on Linux a private Codex seat has a sandbox, so a flag its pods
|
|
5657
|
+
// rule out leaves it there; say so rather than let the flag look applied.
|
|
5658
|
+
if (optedIn && record.adapter === 'codex' && process.platform === 'linux' && !codexUnconfined) {
|
|
5659
|
+
console.warn(`${stamp()} [${name}] ${UNSANDBOXED_FLAG} was not applied: ${
|
|
5660
|
+
effectiveSandboxTrust(record.environment?.sandbox?.trust) === 'workspace'
|
|
5661
|
+
? 'this agent is set to workspace trust'
|
|
5662
|
+
: "a pod this agent answers in isn't confirmed private and invite-only"}, so it runs in Codex's own sandbox.`);
|
|
5663
|
+
}
|
|
5656
5664
|
if (saved && record !== saved) saveAgentToken(name, record);
|
|
5657
5665
|
if (bootstrapped) {
|
|
5658
5666
|
// A named instance is saved under its seat key; an unnamed run keeps
|
|
@@ -46,7 +46,7 @@ import { meetsMinimumVersion, probeVersion, publicCodexVersionError } from './te
|
|
|
46
46
|
import { spawn as childSpawn, spawnSync } from 'child_process';
|
|
47
47
|
import { createHash } from 'crypto';
|
|
48
48
|
import {
|
|
49
|
-
accessSync, constants, existsSync, readFileSync, realpathSync, statSync,
|
|
49
|
+
accessSync, constants, existsSync, readFileSync, readdirSync, realpathSync, statSync,
|
|
50
50
|
} from 'fs';
|
|
51
51
|
import {
|
|
52
52
|
chmod,
|
|
@@ -90,7 +90,7 @@ import { adapterFailure, spawnCredentials } from '../upstream-refusal.js';
|
|
|
90
90
|
import { publicSeatWithheldTools } from '../public-withheld-tools.js';
|
|
91
91
|
import { startProviderProxy } from '../provider-proxy.js';
|
|
92
92
|
import { resolveLaunch, resolveMcpCommand, resolveWindowsCommandWithReason } from '../windows-command.js';
|
|
93
|
-
import { codexContextTokens, codexHomeFor } from '../session-recycle.js';
|
|
93
|
+
import { codexContextTokens, codexHomeFor, codexRolloutPath } from '../session-recycle.js';
|
|
94
94
|
|
|
95
95
|
// Default timeout for a single codex spawn (exec mode).
|
|
96
96
|
//
|
|
@@ -370,10 +370,10 @@ const statOrNull = async (path) => {
|
|
|
370
370
|
// refused. macOS has no arg0 helper and keeps its homes where they were.
|
|
371
371
|
const LEGACY_CODEX_HOMES = (home) => join(home, '.commonly', 'codex-homes');
|
|
372
372
|
|
|
373
|
-
const stateHomeUnderCommonly = (ctx, home) => new Error(
|
|
374
|
-
`XDG_STATE_HOME (${ctx.env?.XDG_STATE_HOME}) puts the
|
|
375
|
-
+
|
|
376
|
-
);
|
|
373
|
+
const stateHomeUnderCommonly = (ctx, home, seat = 'public') => Object.assign(new Error(
|
|
374
|
+
`XDG_STATE_HOME (${ctx.env?.XDG_STATE_HOME}) puts the ${seat} Codex home under ${join(home, '.commonly')}, `
|
|
375
|
+
+ `which the ${seat} sandbox denies on Linux. Point it elsewhere or unset it.`,
|
|
376
|
+
), { code: 'state_home_under_commonly' });
|
|
377
377
|
|
|
378
378
|
const publicCodexHomesRoot = (ctx) => {
|
|
379
379
|
const home = ctx._homeDir || homedir();
|
|
@@ -388,10 +388,117 @@ const publicCodexHomesRoot = (ctx) => {
|
|
|
388
388
|
return root;
|
|
389
389
|
};
|
|
390
390
|
|
|
391
|
+
// An XDG_STATE_HOME under ~/.commonly throws above, and that tree is denied anyway.
|
|
392
|
+
const privatePublicHomesDeny = (ctx) => {
|
|
393
|
+
if ((ctx._platform || process.platform) !== 'linux') return [];
|
|
394
|
+
try {
|
|
395
|
+
return [publicCodexHomesRoot(ctx)];
|
|
396
|
+
} catch {
|
|
397
|
+
return [];
|
|
398
|
+
}
|
|
399
|
+
};
|
|
400
|
+
|
|
391
401
|
const operatorCodexHome = (ctx) => ctx.env?.CODEX_HOME
|
|
392
402
|
|| process.env.CODEX_HOME
|
|
393
403
|
|| join(homedir(), '.codex');
|
|
394
404
|
|
|
405
|
+
// F445: on Linux a private seat runs with a Codex home of its own, beside the
|
|
406
|
+
// public ones, so the folder its shell can see holds no other session's logs,
|
|
407
|
+
// databases or history: F444 denied a shared home entry by entry, from a
|
|
408
|
+
// listing taken when the turn's keys are built, and anything another session
|
|
409
|
+
// wrote there under a new name, or during a command, stayed readable. The home
|
|
410
|
+
// starts with no history: nothing is copied from the shared one, which holds
|
|
411
|
+
// other sessions' history, the thing being fenced off. What the agent is meant
|
|
412
|
+
// to remember lives in Commonly. Only the person's own setup is carried over,
|
|
413
|
+
// as symlinks Codex follows outside the sandbox: their login, config.toml (a
|
|
414
|
+
// private seat keeps its own config) and global AGENTS.md. macOS denies the
|
|
415
|
+
// shared home whole under Seatbelt and keeps running from it.
|
|
416
|
+
const PRIVATE_CODEX_HOMES = 'codex-private-homes';
|
|
417
|
+
const PRIVATE_HOME_LINKS = Object.freeze(['auth.json', 'config.toml', 'AGENTS.md']);
|
|
418
|
+
|
|
419
|
+
/** The shared Codex home a private seat's setup comes from. */
|
|
420
|
+
const privateSourceCodexHome = (ctx, env) => pathResolve(
|
|
421
|
+
ctx.cwd || process.cwd(),
|
|
422
|
+
env?.CODEX_HOME || join(env?.HOME || homedir(), '.codex'),
|
|
423
|
+
);
|
|
424
|
+
|
|
425
|
+
/** Where this private seat's own Codex home is, or null where it has none. */
|
|
426
|
+
export const privateCodexHomePath = (ctx) => {
|
|
427
|
+
if (ctx._privateCodexHome) return ctx._privateCodexHome;
|
|
428
|
+
const identity = ctx.agentName || ctx.cwd || 'anonymous';
|
|
429
|
+
const hash = createHash('sha256').update(`private:${identity}`).digest('hex').slice(0, 20);
|
|
430
|
+
let publicRoot;
|
|
431
|
+
try {
|
|
432
|
+
publicRoot = publicCodexHomesRoot(ctx);
|
|
433
|
+
} catch (error) {
|
|
434
|
+
if (error?.code !== 'state_home_under_commonly') throw error;
|
|
435
|
+
throw stateHomeUnderCommonly(ctx, ctx._homeDir || homedir(), 'private');
|
|
436
|
+
}
|
|
437
|
+
return join(dirname(publicRoot), PRIVATE_CODEX_HOMES, hash);
|
|
438
|
+
};
|
|
439
|
+
|
|
440
|
+
const preparePrivateCodexHome = async (ctx, childEnv) => {
|
|
441
|
+
const source = privateSourceCodexHome(ctx, childEnv);
|
|
442
|
+
const home = privateCodexHomePath(ctx);
|
|
443
|
+
if (pathResolve(home) === source) throw new Error('a private Codex home must be apart from the shared CODEX_HOME');
|
|
444
|
+
const workspacePath = pathResolve(ctx.cwd || process.cwd());
|
|
445
|
+
const userHome = ctx._homeDir || homedir();
|
|
446
|
+
const [workspace, realHome, realSource, realCommonly] = await Promise.all([
|
|
447
|
+
// As in realpathOfNearest: only a missing workspace falls back to its own path.
|
|
448
|
+
realpath(workspacePath).catch((error) => {
|
|
449
|
+
if (error?.code === 'ENOENT') return workspacePath;
|
|
450
|
+
throw error;
|
|
451
|
+
}),
|
|
452
|
+
realpathOfNearest(home),
|
|
453
|
+
realpathOfNearest(source),
|
|
454
|
+
realpathOfNearest(join(userHome, '.commonly')),
|
|
455
|
+
]);
|
|
456
|
+
if (contains(workspace, realHome)) {
|
|
457
|
+
throw new Error(`private codex agents cannot run in ${ctx.cwd}: it contains the agent's own Codex home `
|
|
458
|
+
+ `(${home}), which the sandbox would then expose. Run it in a project folder.`);
|
|
459
|
+
}
|
|
460
|
+
// Both are denied whole, and a home inside either would hide Codex's own
|
|
461
|
+
// sandbox helper, so every turn would stop at start.
|
|
462
|
+
if (contains(realSource, realHome) || contains(realCommonly, realHome)) {
|
|
463
|
+
throw new Error(`a private Codex agent's own home (${home}) resolves inside `
|
|
464
|
+
+ `${contains(realSource, realHome) ? `the shared Codex home (${source})` : join(userHome, '.commonly')}, `
|
|
465
|
+
+ 'which its sandbox denies on Linux. Point XDG_STATE_HOME elsewhere or unset it.');
|
|
466
|
+
}
|
|
467
|
+
await mkdir(home, { recursive: true, mode: 0o700 });
|
|
468
|
+
await chmod(home, 0o700);
|
|
469
|
+
for (const name of PRIVATE_HOME_LINKS) {
|
|
470
|
+
const from = join(source, name);
|
|
471
|
+
const to = join(home, name);
|
|
472
|
+
const [fromStat, toStat] = await Promise.all([statOrNull(from), statOrNull(to)]);
|
|
473
|
+
// A file the seat's Codex wrote in its own home is its own: kept.
|
|
474
|
+
if (toStat && !toStat.isSymbolicLink()) continue;
|
|
475
|
+
if (!fromStat) {
|
|
476
|
+
// A link to a login the person removed would sign in through it anyway.
|
|
477
|
+
if (toStat) await unlink(to);
|
|
478
|
+
continue;
|
|
479
|
+
}
|
|
480
|
+
const current = toStat ? pathResolve(dirname(to), await readlink(to)) : null;
|
|
481
|
+
if (current !== from) {
|
|
482
|
+
if (toStat) await unlink(to);
|
|
483
|
+
// Another turn of the same seat may have just made it.
|
|
484
|
+
await symlink(from, to).catch((error) => { if (error?.code !== 'EEXIST') throw error; });
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
await mkdir(join(home, 'tmp', 'arg0-linux'), { recursive: true, mode: 0o700 });
|
|
488
|
+
// Every other private seat's home, as it stands now. One created during this
|
|
489
|
+
// turn is denied from the next turn on: until then, what that seat's first
|
|
490
|
+
// turn writes there stays readable to this turn's commands.
|
|
491
|
+
const others = entriesOf(dirname(home)).filter((name) => name !== basename(home)).sort()
|
|
492
|
+
.map((name) => join(dirname(home), name));
|
|
493
|
+
// The links into the shared home, which is denied whole with their targets.
|
|
494
|
+
const links = [];
|
|
495
|
+
for (const name of PRIVATE_HOME_LINKS) {
|
|
496
|
+
const stat = await statOrNull(join(home, name));
|
|
497
|
+
if (stat?.isSymbolicLink() && pathResolve(home, await readlink(join(home, name))) === join(source, name)) links.push(name);
|
|
498
|
+
}
|
|
499
|
+
return { home, source, realSource, others, links };
|
|
500
|
+
};
|
|
501
|
+
|
|
395
502
|
// `login: false` is the proxy route (D250): codex authenticates with the
|
|
396
503
|
// per-turn token, so the public home gets no link to the person's Codex login,
|
|
397
504
|
// and a link an earlier turn left is removed.
|
|
@@ -745,10 +852,12 @@ const publicPermissionProfileFlags = (
|
|
|
745
852
|
|
|
746
853
|
// Host secrets a private seat's shell never reads. ~/.commonly holds every
|
|
747
854
|
// seat's tokens and state; the seat's own workspace sits under it and is
|
|
748
|
-
// admitted by the more specific workspace rule
|
|
855
|
+
// admitted by the more specific workspace rule (on Linux too: measured on
|
|
856
|
+
// codex-cli 0.164.0, a write key inside a denied folder works there). The
|
|
857
|
+
// Codex home is privateCodexHomeDenies'. gh keeps working: on macOS its
|
|
749
858
|
// login is in the keychain, which a credential the seat itself uses has to be.
|
|
750
859
|
const PRIVATE_SECRET_DENIES = Object.freeze([
|
|
751
|
-
'~/.commonly', '~/.claude', '~/.
|
|
860
|
+
'~/.commonly', '~/.claude', '~/.ssh', '~/.aws', '~/.gnupg',
|
|
752
861
|
'~/.kube', '~/.docker', '~/.netrc', '~/.config/gcloud',
|
|
753
862
|
]);
|
|
754
863
|
|
|
@@ -760,6 +869,70 @@ const realOrSelf = (path) => {
|
|
|
760
869
|
}
|
|
761
870
|
};
|
|
762
871
|
|
|
872
|
+
// F444: what the private profile denies of the Codex home the seat runs with.
|
|
873
|
+
// On macOS the home is denied whole. On Linux Codex execs its sandbox helper
|
|
874
|
+
// from `<home>/tmp/arg0-linux` inside bwrap, and a denied home stops every turn
|
|
875
|
+
// at start ("bwrap: execvp codex-linux-sandbox: Permission denied"; a read key
|
|
876
|
+
// for `tmp` under the denied home does not lift it). Measured with `codex
|
|
877
|
+
// sandbox` and a real turn on codex-cli 0.164.0, ubuntu-22.04. So there the
|
|
878
|
+
// home itself stays readable and everything in it is denied except the helper
|
|
879
|
+
// folder: each entry present now, and the names Codex writes later even while
|
|
880
|
+
// they are absent (a key for a missing path is accepted there). Codex's SQLite
|
|
881
|
+
// databases write a `-wal` file during the turn that holds their newest rows,
|
|
882
|
+
// other sessions' included, and SQLite removes it when the last connection
|
|
883
|
+
// closes; so every database name, listed or known, takes its `-wal`, `-shm`
|
|
884
|
+
// and `-journal` too. A database under a new name is listed, with those, from
|
|
885
|
+
// the next turn. No globs: Codex's `*` crosses `/`, and a glob that matched a
|
|
886
|
+
// file inside a folder already denied stopped every turn at start ("bwrap:
|
|
887
|
+
// Can't create file at …: Read-only file system", run 43103991434).
|
|
888
|
+
// `~/.codex` is denied whole when it isn't that home.
|
|
889
|
+
const CODEX_HOME_SECRET_NAMES = Object.freeze([
|
|
890
|
+
'auth.json', 'config.toml', 'sessions', 'archived_sessions', 'history.jsonl', 'log',
|
|
891
|
+
'session_index.jsonl', 'shell_snapshots', 'memories',
|
|
892
|
+
'logs_2.sqlite', 'state_5.sqlite', 'goals_1.sqlite', 'queue_1.sqlite',
|
|
893
|
+
]);
|
|
894
|
+
const SQLITE_SIDECARS = Object.freeze(['-wal', '-shm', '-journal']);
|
|
895
|
+
const CODEX_HELPER_PATH = Object.freeze(['tmp', 'arg0-linux']);
|
|
896
|
+
|
|
897
|
+
const entriesOf = (dir) => {
|
|
898
|
+
try {
|
|
899
|
+
return readdirSync(dir);
|
|
900
|
+
} catch {
|
|
901
|
+
return [];
|
|
902
|
+
}
|
|
903
|
+
};
|
|
904
|
+
|
|
905
|
+
// `links`: entries of the run home that are links into a home denied whole
|
|
906
|
+
// (F445). A key on one makes bwrap follow it into the hidden folder and stop
|
|
907
|
+
// every turn at start ("Can't create file at …/auth.json: No such file or
|
|
908
|
+
// directory", run 43114789288); its target is out of reach already.
|
|
909
|
+
export const privateCodexHomeDenies = ({
|
|
910
|
+
codexHome = null, platform = process.platform, home = homedir(), links = [],
|
|
911
|
+
} = {}) => {
|
|
912
|
+
const defaultHome = join(home, '.codex');
|
|
913
|
+
const runHome = codexHome ? realOrSelf(codexHome) : null;
|
|
914
|
+
const runsFromDefault = !runHome || runHome === realOrSelf(defaultHome);
|
|
915
|
+
if (platform !== 'linux') return runsFromDefault ? ['~/.codex'] : ['~/.codex', runHome];
|
|
916
|
+
const helperHome = runHome || realOrSelf(defaultHome);
|
|
917
|
+
const denies = runsFromDefault ? [] : ['~/.codex'];
|
|
918
|
+
// Deny every sibling of the helper path at each level, so only the path
|
|
919
|
+
// itself stays reachable.
|
|
920
|
+
let dir = helperHome;
|
|
921
|
+
for (const [depth, keep] of CODEX_HELPER_PATH.entries()) {
|
|
922
|
+
const names = new Set(entriesOf(dir));
|
|
923
|
+
if (depth === 0) {
|
|
924
|
+
CODEX_HOME_SECRET_NAMES.forEach((name) => names.add(name));
|
|
925
|
+
[...names].filter((name) => /\.(sqlite|db)$/.test(name))
|
|
926
|
+
.forEach((name) => SQLITE_SIDECARS.forEach((suffix) => names.add(`${name}${suffix}`)));
|
|
927
|
+
}
|
|
928
|
+
names.delete(keep);
|
|
929
|
+
if (depth === 0) links.forEach((name) => names.delete(name));
|
|
930
|
+
denies.push(...[...names].sort().map((name) => join(dir, name)));
|
|
931
|
+
dir = join(dir, keep);
|
|
932
|
+
}
|
|
933
|
+
return denies;
|
|
934
|
+
};
|
|
935
|
+
|
|
763
936
|
// What a commit writes, and nothing that runs code. Codex keeps a workspace's
|
|
764
937
|
// `.git` read-only even inside a writable root, and only an explicit absolute
|
|
765
938
|
// key opens it (measured with `codex sandbox` on 0.162.1: the same key inside
|
|
@@ -828,6 +1001,10 @@ const privatePermissionProfileFlags = ({
|
|
|
828
1001
|
workspace = null,
|
|
829
1002
|
tempRoots = [],
|
|
830
1003
|
shellTempDir = null,
|
|
1004
|
+
codexHome = null,
|
|
1005
|
+
home = homedir(),
|
|
1006
|
+
otherCodexHomes = [],
|
|
1007
|
+
codexHomeLinks = [],
|
|
831
1008
|
} = {}) => {
|
|
832
1009
|
const { commitHooksPath, originalHookPaths } = commitHookReadPaths(commitAttributionEnv);
|
|
833
1010
|
const posix = platform !== 'win32';
|
|
@@ -845,7 +1022,8 @@ const privatePermissionProfileFlags = ({
|
|
|
845
1022
|
// no drive and Codex would refuse the whole profile (as with /private/tmp
|
|
846
1023
|
// in publicPermissionProfileFlags).
|
|
847
1024
|
posix ? '"/"="read"' : '":minimal"="read"',
|
|
848
|
-
...PRIVATE_SECRET_DENIES
|
|
1025
|
+
...[...PRIVATE_SECRET_DENIES, ...privateCodexHomeDenies({ codexHome, platform, home, links: codexHomeLinks }), ...otherCodexHomes]
|
|
1026
|
+
.map((path) => `${toml(path)}="deny"`),
|
|
849
1027
|
...deniedTemp.map((path) => `${toml(path)}="deny"`),
|
|
850
1028
|
...(shellTemp ? [`${toml(shellTemp)}="write"`] : []),
|
|
851
1029
|
'":workspace_roots"={"."="write",".commonly/**"="deny",".codex/**"="deny"}',
|
|
@@ -994,6 +1172,10 @@ const buildArgs = ({
|
|
|
994
1172
|
privateWorkspace = null,
|
|
995
1173
|
tempRoots = [],
|
|
996
1174
|
shellTempDir = null,
|
|
1175
|
+
privateCodexHome = null,
|
|
1176
|
+
privateHome = homedir(),
|
|
1177
|
+
privateOtherCodexHomes = [],
|
|
1178
|
+
privateCodexHomeLinks = [],
|
|
997
1179
|
}) => {
|
|
998
1180
|
const publicSandbox = publicSandboxMode !== null;
|
|
999
1181
|
// F387: a private seat keeps the flag below only in a cloud-codex pod, or
|
|
@@ -1049,6 +1231,10 @@ const buildArgs = ({
|
|
|
1049
1231
|
workspace: privateWorkspace,
|
|
1050
1232
|
tempRoots,
|
|
1051
1233
|
shellTempDir,
|
|
1234
|
+
codexHome: privateCodexHome,
|
|
1235
|
+
home: privateHome,
|
|
1236
|
+
otherCodexHomes: privateOtherCodexHomes,
|
|
1237
|
+
codexHomeLinks: privateCodexHomeLinks,
|
|
1052
1238
|
});
|
|
1053
1239
|
const common = [
|
|
1054
1240
|
'--json',
|
|
@@ -1274,8 +1460,20 @@ export default {
|
|
|
1274
1460
|
// alone. claude.js adds parallel reads, whose cue names Claude's Agent tool;
|
|
1275
1461
|
// Codex has agent tools of its own, under other names. A public seat answers
|
|
1276
1462
|
// strangers rather than working board rows, so it is taught neither.
|
|
1463
|
+
// F445: a private seat on Linux resumes only a thread in its own Codex
|
|
1464
|
+
// home; one in the shared home (a run before F445) starts fresh, which the
|
|
1465
|
+
// prompt has to know.
|
|
1466
|
+
const ownPrivateHome = (ctx._platform || process.platform) === 'linux' && sandbox?.trust !== 'public'
|
|
1467
|
+
&& !codexTrustedPerimeter(ctx.env || process.env) && ctx.hostUnconfined !== true
|
|
1468
|
+
? privateCodexHomePath(ctx) : null;
|
|
1469
|
+
let sessionId = ctx.sessionId || null;
|
|
1470
|
+
if (ownPrivateHome && sessionId && !codexRolloutPath({ codexHome: ownPrivateHome, sessionId })) {
|
|
1471
|
+
process.stderr.write('[codex] this agent now keeps its own Codex home, so it starts a new thread; '
|
|
1472
|
+
+ 'what it is meant to remember is in its Commonly memory.\n');
|
|
1473
|
+
sessionId = null;
|
|
1474
|
+
}
|
|
1277
1475
|
const fullPrompt = buildPrompt(prompt, ctx.memoryLongTerm, {
|
|
1278
|
-
freshSession: !
|
|
1476
|
+
freshSession: !sessionId,
|
|
1279
1477
|
workCues: sandbox?.trust === 'public' ? [] : [ROW_SLICING_CUE, BACKGROUND_PROCESS_CUE],
|
|
1280
1478
|
// F118: a public seat reads its memory but is not offered a write.
|
|
1281
1479
|
memoryReadOnly: sandbox?.trust === 'public' && ctx.ownerWoken !== true,
|
|
@@ -1417,6 +1615,9 @@ export default {
|
|
|
1417
1615
|
const publicCodexHome = publicSandboxMode !== null
|
|
1418
1616
|
? await preparePublicCodexHome(ctx, childEnv, { login: !route })
|
|
1419
1617
|
: null;
|
|
1618
|
+
const privateCodexHome = privateProfile && ownPrivateHome
|
|
1619
|
+
? await preparePrivateCodexHome(ctx, childEnv)
|
|
1620
|
+
: null;
|
|
1420
1621
|
// The private shell's TMPDIR: inside this turn's folder, which `finally`
|
|
1421
1622
|
// removes, and beside (not over) the token's folder.
|
|
1422
1623
|
const privateShellTemp = privateProfile ? join(dir, 'shell-tmp') : null;
|
|
@@ -1431,7 +1632,7 @@ export default {
|
|
|
1431
1632
|
childEnv[CODEX_PROVIDER_TOKEN_ENV] = providerProxy.token;
|
|
1432
1633
|
}
|
|
1433
1634
|
const args = buildArgs({
|
|
1434
|
-
sessionId
|
|
1635
|
+
sessionId,
|
|
1435
1636
|
prompt: fullPrompt,
|
|
1436
1637
|
outputFile,
|
|
1437
1638
|
mcpFlags: mcp.flags,
|
|
@@ -1455,6 +1656,25 @@ export default {
|
|
|
1455
1656
|
// lives, and the one the shell would inherit.
|
|
1456
1657
|
tempRoots: privateProfile ? [tmpdir(), childEnv.TMPDIR] : [],
|
|
1457
1658
|
shellTempDir: privateShellTemp,
|
|
1659
|
+
// The home Codex runs with, and the HOME its `~` keys expand against.
|
|
1660
|
+
// Codex reads a relative CODEX_HOME from its own folder, the turn's.
|
|
1661
|
+
privateCodexHome: privateProfile
|
|
1662
|
+
? privateCodexHome?.home || privateSourceCodexHome(ctx, childEnv)
|
|
1663
|
+
: null,
|
|
1664
|
+
privateHome: childEnv.HOME || homedir(),
|
|
1665
|
+
// Public seats' Codex homes (their sessions and logs): under the denied
|
|
1666
|
+
// ~/.commonly on macOS, outside it on Linux. With a home of its own, the
|
|
1667
|
+
// shared one it came from and every other private seat's are denied whole.
|
|
1668
|
+
privateOtherCodexHomes: privateProfile
|
|
1669
|
+
? [...new Set([
|
|
1670
|
+
...privatePublicHomesDeny(ctx),
|
|
1671
|
+
// By its real path too, when it is a link to another folder.
|
|
1672
|
+
...(privateCodexHome
|
|
1673
|
+
? [privateCodexHome.source, privateCodexHome.realSource, ...privateCodexHome.others]
|
|
1674
|
+
: []),
|
|
1675
|
+
])]
|
|
1676
|
+
: [],
|
|
1677
|
+
privateCodexHomeLinks: privateCodexHome?.links || [],
|
|
1458
1678
|
});
|
|
1459
1679
|
// childEnv is derived from the process environment, so the bootstrap export has to be
|
|
1460
1680
|
// taken back out: the declaration above moved our server onto the file,
|
|
@@ -1472,6 +1692,7 @@ export default {
|
|
|
1472
1692
|
childEnv.CODEX_HOME = publicCodexHome.home;
|
|
1473
1693
|
await writePublicCodexInstructions(childEnv.CODEX_HOME, ctx);
|
|
1474
1694
|
}
|
|
1695
|
+
if (privateCodexHome) childEnv.CODEX_HOME = privateCodexHome.home;
|
|
1475
1696
|
|
|
1476
1697
|
// The awaits above can outlast a supervisor stall window. Once it has
|
|
1477
1698
|
// aborted, the attempt has already settled and a retry may be running,
|
|
@@ -1522,7 +1743,7 @@ export default {
|
|
|
1522
1743
|
// a new session, often re-emitted on resume) > the persisted id we
|
|
1523
1744
|
// came in with > null. The wrapper persists whichever non-null value
|
|
1524
1745
|
// we return so subsequent turns hit `codex exec resume <id>`.
|
|
1525
|
-
const newSessionId = threadId ||
|
|
1746
|
+
const newSessionId = threadId || sessionId || null;
|
|
1526
1747
|
// F404: what the turn's last request was sent, from the rollout the child
|
|
1527
1748
|
// wrote under its own CODEX_HOME. Null keeps resuming.
|
|
1528
1749
|
const contextTokens = newSessionId
|
|
@@ -122,28 +122,47 @@ export const bwrapRefusedMessage = (adapterName, { reason, apparmorRestricted, u
|
|
|
122
122
|
].join('\n');
|
|
123
123
|
};
|
|
124
124
|
|
|
125
|
+
const CODEX_UNSANDBOXED_RUN_LINE = ` - In invite-only pods, run it without a sandbox: ${CLI} agent run <name> ${UNSANDBOXED_FLAG}`
|
|
126
|
+
+ ' (in the foreground; the daemon takes this only on Windows).'
|
|
127
|
+
+ ' Nothing confines it: it runs with your own access to files and commands, anyone in the pod,'
|
|
128
|
+
+ ' people you invite later included, can direct it, and it gets no connector grants.';
|
|
129
|
+
|
|
125
130
|
/**
|
|
126
|
-
* F387: a private Codex seat on Linux
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
131
|
+
* F387, F444: a private Codex seat on Linux runs under Codex's own sandbox,
|
|
132
|
+
* which uses bubblewrap there. Where bubblewrap can't start one, the seat is
|
|
133
|
+
* refused before its first poll, with the fix for this host. The person can
|
|
134
|
+
* run it unconfined by their own choice, as on native Windows; it never falls
|
|
135
|
+
* back to that without being asked.
|
|
130
136
|
*/
|
|
131
|
-
export const
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
137
|
+
export const codexPrivateLinuxMessage = (bwrap = {}, { optedIn = false } = {}) => {
|
|
138
|
+
const refused = bwrap.namespaceRefused === true;
|
|
139
|
+
const offersProfile = refused && bwrap.apparmorRestricted === true && bwrap.ubuntuRelease === '24.04';
|
|
140
|
+
return [
|
|
141
|
+
'A private Codex agent runs inside Codex\'s own sandbox, which keeps your other credentials out of its reach'
|
|
142
|
+
+ ` and uses bubblewrap on Linux. ${refused
|
|
143
|
+
? `This machine won't let bubblewrap start one (${bwrap.reason}).`
|
|
144
|
+
: (bwrap.error || 'bubblewrap was not found.')}`,
|
|
145
|
+
...(refused && bwrap.apparmorRestricted === true
|
|
146
|
+
? ['AppArmor on Ubuntu 24.04 and later restricts the user namespaces bubblewrap needs.']
|
|
147
|
+
: []),
|
|
148
|
+
...(optedIn
|
|
149
|
+
? ['A pod this agent answers in is publicly readable or open to join, or did not report whether it is,'
|
|
150
|
+
+ ' so it cannot run without a sandbox either.']
|
|
151
|
+
: []),
|
|
152
|
+
'So this agent cannot listen for @mentions here yet. You can:',
|
|
153
|
+
...(refused ? [] : [' - Install bubblewrap (`sudo apt install bubblewrap`) and run the same command again.']),
|
|
154
|
+
...(optedIn ? [] : [CODEX_UNSANDBOXED_RUN_LINE]),
|
|
155
|
+
HOSTED_LINE,
|
|
156
|
+
...(offersProfile ? UBUNTU_BWRAP_PROFILE_LINES : []),
|
|
157
|
+
].join('\n');
|
|
158
|
+
};
|
|
140
159
|
|
|
141
|
-
// The person opted in, and a pod rules it out
|
|
142
|
-
//
|
|
143
|
-
|
|
160
|
+
// The person opted in, and a pod rules it out, so the turn has no sandbox to
|
|
161
|
+
// fall back to on any platform. Naming the flag again would only send them
|
|
162
|
+
// round in a circle.
|
|
163
|
+
export const CODEX_OPTED_IN_PUBLIC_POD_MESSAGE = [
|
|
144
164
|
'A pod this agent answers in is publicly readable or open to join, or did not report whether it is,',
|
|
145
|
-
'so it cannot run without a sandbox
|
|
146
|
-
' - Run it on a Mac, where the sandbox is ready.',
|
|
165
|
+
'so it cannot run without a sandbox. You can:',
|
|
147
166
|
HOSTED_LINE,
|
|
148
167
|
].join('\n');
|
|
149
168
|
|
|
@@ -200,17 +219,18 @@ export const hostSandboxRefusal = ({
|
|
|
200
219
|
const bwrap = detectBwrap();
|
|
201
220
|
return bwrap.namespaceRefused === true ? bwrapRefusedMessage(adapterName, bwrap) : null;
|
|
202
221
|
}
|
|
203
|
-
// F387: a private seat outside a cloud-codex pod runs under the
|
|
204
|
-
// permission profile
|
|
205
|
-
//
|
|
206
|
-
//
|
|
207
|
-
//
|
|
208
|
-
//
|
|
209
|
-
//
|
|
210
|
-
// confirmed private). Never unconfined without being asked.
|
|
222
|
+
// F387, F444: a private seat outside a cloud-codex pod runs under the
|
|
223
|
+
// private permission profile, which Codex enforces with bubblewrap on Linux
|
|
224
|
+
// (walked on byo-linux.yml, walk=private-codex). Where bubblewrap can't
|
|
225
|
+
// start, every turn would fail at session start, so the seat is refused
|
|
226
|
+
// before its first poll, unless the person ran it unconfined by their own
|
|
227
|
+
// --unsandboxed (D245, as on Windows: only with every pod confirmed
|
|
228
|
+
// private). Never unconfined without being asked.
|
|
211
229
|
if (platform === 'linux' && trust !== 'workspace' && !codexTrustedPerimeter(env)) {
|
|
212
230
|
if (hostUnconfined === true) return null;
|
|
213
|
-
|
|
231
|
+
const bwrap = detectBwrap();
|
|
232
|
+
if (bwrap.available) return null;
|
|
233
|
+
return codexPrivateLinuxMessage(bwrap, { optedIn: optedIn === true });
|
|
214
234
|
}
|
|
215
235
|
if (platform !== 'win32') return null;
|
|
216
236
|
if (trust === 'workspace') return null;
|
|
@@ -55,8 +55,8 @@ export const unsandboxedMarkerPath = (home = homedir()) => join(home, '.commonly
|
|
|
55
55
|
|
|
56
56
|
/**
|
|
57
57
|
* The flag answers a gap in the sandbox: native Windows has none, and a private
|
|
58
|
-
* Codex agent on Linux has none
|
|
59
|
-
* only for `agent run` of a Codex agent: pass `adapterName` once it is known,
|
|
58
|
+
* Codex agent on Linux has none where bubblewrap can't start (F387, F444). So
|
|
59
|
+
* on Linux it is accepted only for `agent run` of a Codex agent: pass `adapterName` once it is known,
|
|
60
60
|
* or `deferred` before the record is read (the run checks again after). The
|
|
61
61
|
* daemon's marker stays Windows-only.
|
|
62
62
|
*/
|
|
@@ -123,9 +123,8 @@ export const hostUnconfinedForRun = ({
|
|
|
123
123
|
};
|
|
124
124
|
|
|
125
125
|
/**
|
|
126
|
-
* Does this Codex run go unconfined? Only on win32, or on Linux
|
|
127
|
-
*
|
|
128
|
-
* opt-in, and only when every pod the seat answers in is confirmed private:
|
|
126
|
+
* Does this Codex run go unconfined? Only on win32, or on Linux (F387, F444),
|
|
127
|
+
* only by the user's own opt-in, and only when every pod the seat answers in is confirmed private:
|
|
129
128
|
* `installations` is the server's read of them, and an empty or failed read is
|
|
130
129
|
* a no. Workspace trust stays with Codex's own refusal. The caller removes the
|
|
131
130
|
* sandbox block for this run only, so the saved record keeps its public trust
|
|
@@ -152,7 +151,7 @@ export const UNSANDBOXED_NOTICE = 'unsandboxed (opted in): Windows has no sandbo
|
|
|
152
151
|
/** Codex has no restricted tool settings to keep, so its line says what it costs instead. */
|
|
153
152
|
export const CODEX_UNSANDBOXED_NOTICE = 'unsandboxed (opted in): Windows has no sandbox Codex can use here, so nothing confines this agent. It runs with your own access to files and commands, and anyone in its pods, people invited later included, can direct it. It gets no connector grants, and a turn is refused if a pod stops being invite-only.';
|
|
154
153
|
|
|
155
|
-
export const CODEX_LINUX_UNSANDBOXED_NOTICE = 'unsandboxed (opted in):
|
|
154
|
+
export const CODEX_LINUX_UNSANDBOXED_NOTICE = 'unsandboxed (opted in): you ran this Codex agent without its sandbox, so nothing confines this agent. It runs with your own access to files and commands, and anyone in its pods, people invited later included, can direct it. It gets no connector grants, and a turn is refused if a pod stops being invite-only.';
|
|
156
155
|
|
|
157
156
|
export const codexUnsandboxedNotice = (platform = process.platform) => (platform === 'linux'
|
|
158
157
|
? CODEX_LINUX_UNSANDBOXED_NOTICE
|