talentos 1.3.0 → 1.4.1
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/dist/agent/adapters.js +23 -0
- package/dist/agent/codex-policy.js +3 -0
- package/dist/agent/gateway.js +11 -1
- package/dist/agent/mcp-entry.js +4 -1
- package/dist/agent/native/codex-fence-probe.js +629 -0
- package/dist/agent/native/codex-fence.js +168 -0
- package/dist/agent/native/codex-launch.js +86 -0
- package/dist/agent/native/codex-owner-probe.js +145 -4
- package/dist/agent/native/codex-run-command.js +302 -0
- package/dist/agent/native/config.js +8 -2
- package/dist/agent/native/discover.js +137 -0
- package/dist/agent/native/fresh.js +104 -0
- package/dist/agent/native/gate.js +139 -17
- package/dist/agent/native/policy.js +63 -14
- package/dist/agent/native/project-requests.js +106 -0
- package/dist/agent/native/projects.js +111 -0
- package/dist/agent/native/touch.js +10 -0
- package/dist/agent/native/workspace.js +20 -5
- package/dist/agent/serve.js +59 -5
- package/dist/args.js +1 -0
- package/dist/commands/agent-native.js +39 -5
- package/dist/commands/agent.js +5 -1
- package/dist/mcp-proxy.js +25 -2
- package/package.json +1 -1
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { ROOM_LOCAL_TOOLS, ROOM_TOOLS } from "../codex-policy.js";
|
|
2
|
+
// The owner-native Codex fence (#10987 slice 1): the launch that turns a Codex
|
|
3
|
+
// whose shell is NOT hookable (write_stdin into an open exec_command session
|
|
4
|
+
// runs with no hook call, on every version through 0.164.0-alpha.3 — see
|
|
5
|
+
// codex-owner-probe.ts) into one that is safe to run the owner's real setup.
|
|
6
|
+
//
|
|
7
|
+
// The fence has three parts, proven by codex-fence-probe.ts before any version
|
|
8
|
+
// is allowed to run owner-native:
|
|
9
|
+
// 1. A per-run model catalog sets every model's shell_type="disabled", which
|
|
10
|
+
// drops exec_command AND write_stdin together (no knob keeps write_stdin
|
|
11
|
+
// without exec_command). apply_patch and view_image stay, both hooked.
|
|
12
|
+
// 2. run_command, served by our LOCAL stdio proxy, is the only way to run a
|
|
13
|
+
// command; the proxy classifies it through the same hook as Claude's Bash.
|
|
14
|
+
// 3. Everything the hook cannot see is turned off (web search, image
|
|
15
|
+
// generation, goals, tool search, request_user_input, multi-agent), so the
|
|
16
|
+
// session's whole tool list is exactly the allowlist below.
|
|
17
|
+
export const ROOM_SERVER = "talentos_room";
|
|
18
|
+
// R2 (#10987): a version pin both ways. Owner-native Codex runs only on a
|
|
19
|
+
// version at or above the minimum AND in the exact tested set; an untested newer
|
|
20
|
+
// Codex falls back to room-only until probeCodexFence re-runs on it and this set
|
|
21
|
+
// grows. The minimum is npm `latest` at the time of the gate. These are the
|
|
22
|
+
// EXACT npm version strings probed (`codex --version`'s numeric form parses the
|
|
23
|
+
// alpha to 0.164.0). 0.162.1 also passes the fence but stays below the pin.
|
|
24
|
+
// Enforced by the claim/gate (slice 2).
|
|
25
|
+
export const CODEX_FENCE_MIN_VERSION = "0.163.0";
|
|
26
|
+
export const CODEX_FENCE_TESTED = ["0.163.0", "0.164.0-alpha.3"];
|
|
27
|
+
// The FULL version including any prerelease: `codex --version` prints
|
|
28
|
+
// "codex-cli 0.164.0-alpha.3", and dropping "-alpha.3" would both fail to match
|
|
29
|
+
// a tested alpha and wrongly admit an untested stable 0.164.0. The gate
|
|
30
|
+
// exact-matches this against the tested set, so a version we have not probed —
|
|
31
|
+
// including a newer stable — stays room-only until probeCodexFence re-runs.
|
|
32
|
+
const CODEX_VERSION_FULL = /(\d+\.\d+\.\d+(?:-[0-9A-Za-z.]+)?)/u;
|
|
33
|
+
export function codexFenceVersion(versionOutput) {
|
|
34
|
+
return CODEX_VERSION_FULL.exec(versionOutput)?.[1];
|
|
35
|
+
}
|
|
36
|
+
/** What `talentos agent native enable` tells the owner about an untested Codex. */
|
|
37
|
+
export function codexUnsupportedMessage(versionOutput) {
|
|
38
|
+
const version = codexFenceVersion(versionOutput) ?? "unknown version";
|
|
39
|
+
return `Your Codex (${version}) isn't verified for full setup yet, so it works room-only. Works with: ${CODEX_FENCE_TESTED.join(", ")}. Install one of those, then run talentos agent native enable again.`;
|
|
40
|
+
}
|
|
41
|
+
/** Whether this exact Codex version has passed the fence gate (R2). */
|
|
42
|
+
export function codexFenceEligible(versionOutput) {
|
|
43
|
+
const version = codexFenceVersion(versionOutput);
|
|
44
|
+
return (version !== undefined &&
|
|
45
|
+
CODEX_FENCE_TESTED.includes(version));
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The session's complete tool surface in an owner-native Codex job. The gate
|
|
49
|
+
* probe fails closed unless the live tool list equals this exactly (an
|
|
50
|
+
* allowlist, never a denylist: a future shell variant that the catalog did not
|
|
51
|
+
* remove is a new name here, so it fails). The three list/read MCP-resource
|
|
52
|
+
* tools are Codex builtins present whenever any MCP server is configured; they
|
|
53
|
+
* are inert because our room server exposes no resources, and the hook holds
|
|
54
|
+
* read_mcp_resource like any unknown tool.
|
|
55
|
+
*/
|
|
56
|
+
export function ownerToolAllowlist(roomTools = [...ROOM_TOOLS, ...ROOM_LOCAL_TOOLS]) {
|
|
57
|
+
return new Set([
|
|
58
|
+
"apply_patch",
|
|
59
|
+
"view_image",
|
|
60
|
+
"list_mcp_resources",
|
|
61
|
+
"list_mcp_resource_templates",
|
|
62
|
+
"read_mcp_resource",
|
|
63
|
+
...roomTools.map((tool) => `mcp__${ROOM_SERVER}__${tool}`),
|
|
64
|
+
]);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* The owner-native catalog: the bundled catalog with every model's shell
|
|
68
|
+
* removed (shell_type="disabled", node_repl off) and the hosted web-search tool
|
|
69
|
+
* off, keeping apply_patch and the model's own tool mode (code or direct) so the
|
|
70
|
+
* fence holds in both. A model missing from the bundled catalog cannot appear,
|
|
71
|
+
* so a model with no entry has no shell to fall back to. Throws on a catalog
|
|
72
|
+
* shape it does not recognise, so the launch fails closed rather than guessing.
|
|
73
|
+
*/
|
|
74
|
+
export function ownerCatalog(bundled) {
|
|
75
|
+
const catalog = JSON.parse(bundled);
|
|
76
|
+
if (!Array.isArray(catalog.models) || catalog.models.length === 0) {
|
|
77
|
+
throw new Error("Unsupported model catalog");
|
|
78
|
+
}
|
|
79
|
+
const models = catalog.models.map((model) => {
|
|
80
|
+
if (!model ||
|
|
81
|
+
typeof model !== "object" ||
|
|
82
|
+
!("slug" in model) ||
|
|
83
|
+
!("shell_type" in model)) {
|
|
84
|
+
throw new Error("Unsupported model catalog entry");
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
...model,
|
|
88
|
+
// Drops exec_command and write_stdin together; nothing else does.
|
|
89
|
+
shell_type: "disabled",
|
|
90
|
+
node_repl_disabled: true,
|
|
91
|
+
node_repl_auto_review_required: true,
|
|
92
|
+
// The hook cannot see the hosted web-search or the clock tool.
|
|
93
|
+
supports_search_tool: false,
|
|
94
|
+
experimental_supported_tools: [],
|
|
95
|
+
};
|
|
96
|
+
});
|
|
97
|
+
return JSON.stringify({ ...catalog, models });
|
|
98
|
+
}
|
|
99
|
+
// Everything the hook cannot see, turned off so the tool list is the allowlist.
|
|
100
|
+
// Kept ON: apply_patch (freeform, hooked every path), view_image (hooked), the
|
|
101
|
+
// room MCP server (room tools + run_command). Multi-agent is off in slice 1, so
|
|
102
|
+
// no subagent can reach a tool the parent cannot; it is a stated v1 gap.
|
|
103
|
+
const OWNER_FEATURE_ARGS = [
|
|
104
|
+
'web_search="disabled"',
|
|
105
|
+
"features.view_image=true",
|
|
106
|
+
"features.image_generation=false",
|
|
107
|
+
"features.apps=false",
|
|
108
|
+
"features.plugins=false",
|
|
109
|
+
"features.tool_search=false",
|
|
110
|
+
"features.goals=false",
|
|
111
|
+
"features.multi_agent=false",
|
|
112
|
+
"agents.enabled=false",
|
|
113
|
+
"tools.experimental_request_user_input.enabled=false",
|
|
114
|
+
"memories.generate_memories=false",
|
|
115
|
+
];
|
|
116
|
+
/**
|
|
117
|
+
* The owner-native launch arguments, minus the hook-trust argument (built
|
|
118
|
+
* asynchronously from the app server by the caller) and the inline hook
|
|
119
|
+
* argument (codexHookArgs). approval_policy is "never" because our hook, not
|
|
120
|
+
* Codex's own prompt, decides; the OS sandbox (workspace-write, network off) is
|
|
121
|
+
* a backstop layer, never the gate, and run_command runs one-shot in the proxy
|
|
122
|
+
* outside it.
|
|
123
|
+
*/
|
|
124
|
+
export function codexOwnerArgs(input) {
|
|
125
|
+
const args = [
|
|
126
|
+
"-c",
|
|
127
|
+
'sandbox_mode="workspace-write"',
|
|
128
|
+
"-c",
|
|
129
|
+
`sandbox_workspace_write.writable_roots=${JSON.stringify([input.writableRoot])}`,
|
|
130
|
+
"-c",
|
|
131
|
+
"sandbox_workspace_write.network_access=false",
|
|
132
|
+
"-c",
|
|
133
|
+
'approval_policy="never"',
|
|
134
|
+
...OWNER_FEATURE_ARGS.flatMap((flag) => ["-c", flag]),
|
|
135
|
+
"-c",
|
|
136
|
+
`model_catalog_json=${JSON.stringify(input.catalogPath)}`,
|
|
137
|
+
"-c",
|
|
138
|
+
`mcp_servers.${ROOM_SERVER}.enabled_tools=${JSON.stringify([
|
|
139
|
+
...ROOM_TOOLS,
|
|
140
|
+
...ROOM_LOCAL_TOOLS,
|
|
141
|
+
])}`,
|
|
142
|
+
// Our PreToolUse hook is the gate, so Codex must not add its own approval
|
|
143
|
+
// prompt in front of the room server (under workspace-write an MCP call
|
|
144
|
+
// would otherwise be refused as "requires approval, but policy is never").
|
|
145
|
+
"-c",
|
|
146
|
+
`mcp_servers.${ROOM_SERVER}.default_tools_approval_mode="approve"`,
|
|
147
|
+
// run_command holds for the owner's approval then runs, so the room server's
|
|
148
|
+
// per-tool-call timeout must cover the hold (up to ~900 s) plus the 600 s
|
|
149
|
+
// command cap. This PER-SERVER key is the one that governs an MCP tool call
|
|
150
|
+
// (measured: mcp_servers.<s>.tool_timeout_sec=10 cuts a 40 s call; the global
|
|
151
|
+
// tool_timeout_sec does not, and the ~300 s default would otherwise cut a
|
|
152
|
+
// long approval hold short — "owner taps Allow and nothing happens").
|
|
153
|
+
"-c",
|
|
154
|
+
`mcp_servers.${ROOM_SERVER}.tool_timeout_sec=1800`,
|
|
155
|
+
"-c",
|
|
156
|
+
`mcp_servers.${ROOM_SERVER}.command=${JSON.stringify(input.mcpCommand)}`,
|
|
157
|
+
"-c",
|
|
158
|
+
`mcp_servers.${ROOM_SERVER}.args=${JSON.stringify(input.mcpArgs)}`,
|
|
159
|
+
"exec",
|
|
160
|
+
];
|
|
161
|
+
if (input.sessionId) {
|
|
162
|
+
args.push("resume", input.sessionId);
|
|
163
|
+
}
|
|
164
|
+
// --ignore-user-config is NOT passed: owner-native loads the owner's ~/.codex
|
|
165
|
+
// setup. What that implies for the shared-room review gate is slice 2.
|
|
166
|
+
args.push("--json", "--skip-git-repo-check", input.prompt);
|
|
167
|
+
return args;
|
|
168
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { mkdir, rm } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { writePrivateFile } from "../../agent-config.js";
|
|
5
|
+
import { gatewayLauncherPath } from "../../gateway-install.js";
|
|
6
|
+
import { codexOwnerArgs, ownerCatalog } from "./codex-fence.js";
|
|
7
|
+
import { codexHookArgs, trustHookArgs } from "./codex-owner.js";
|
|
8
|
+
import { HOOK_ENTRY, ownerRules } from "./launch.js";
|
|
9
|
+
/** The room MCP proxy command for a Codex owner job: adds the owner job dir. */
|
|
10
|
+
export function codexRoomMcpEntry(input) {
|
|
11
|
+
const launcher = gatewayLauncherPath(input.home);
|
|
12
|
+
const useLauncher = process.platform !== "win32";
|
|
13
|
+
return {
|
|
14
|
+
command: useLauncher ? launcher : process.execPath,
|
|
15
|
+
args: [
|
|
16
|
+
...(useLauncher
|
|
17
|
+
? []
|
|
18
|
+
: [fileURLToPath(new URL("../../index.js", import.meta.url))]),
|
|
19
|
+
"agent",
|
|
20
|
+
"mcp",
|
|
21
|
+
"--agent",
|
|
22
|
+
input.agentId,
|
|
23
|
+
...(input.uploadRoot ? ["--upload-root", input.uploadRoot] : []),
|
|
24
|
+
// Turns on run_command, served and gated by the proxy for this job only.
|
|
25
|
+
"--owner-job-dir",
|
|
26
|
+
input.jobDir,
|
|
27
|
+
],
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export async function prepareCodexOwnerLaunch(input) {
|
|
31
|
+
const jobDir = join(input.directory, "jobs", input.jobId.replace(/[^\w-]/gu, ""));
|
|
32
|
+
await mkdir(jobDir, { recursive: true, mode: 0o700 });
|
|
33
|
+
await writePrivateFile(join(jobDir, "context.json"), JSON.stringify({
|
|
34
|
+
...(input.askSocket ? { askSocket: input.askSocket } : {}),
|
|
35
|
+
home: input.home,
|
|
36
|
+
writeRoots: input.workspace.writeRoots,
|
|
37
|
+
}));
|
|
38
|
+
const catalogPath = join(jobDir, "catalog.json");
|
|
39
|
+
await writePrivateFile(catalogPath, ownerCatalog(input.bundledCatalog));
|
|
40
|
+
// A tiny per-job wrapper so the hook is a single executable path (as Codex's
|
|
41
|
+
// hook runner expects) that carries this job's folder, like Claude's hook.
|
|
42
|
+
const hookPath = join(jobDir, "hook.sh");
|
|
43
|
+
await writePrivateFile(hookPath, `#!/bin/sh\nexec ${shellQuote(process.execPath)} ${shellQuote(HOOK_ENTRY)} ${shellQuote(jobDir)}\n`, 0o700);
|
|
44
|
+
const trust = input.trust ?? trustHookArgs;
|
|
45
|
+
const trustArgs = await trust({
|
|
46
|
+
binary: input.binary,
|
|
47
|
+
command: hookPath,
|
|
48
|
+
cwd: input.workspace.cwd,
|
|
49
|
+
env: input.env,
|
|
50
|
+
signal: input.signal,
|
|
51
|
+
});
|
|
52
|
+
const mcp = codexRoomMcpEntry({
|
|
53
|
+
agentId: input.agentId,
|
|
54
|
+
home: input.home,
|
|
55
|
+
jobDir,
|
|
56
|
+
uploadRoot: input.workspace.writeRoots[0],
|
|
57
|
+
});
|
|
58
|
+
const args = [
|
|
59
|
+
// The owner's own setup reaches the model as data (room is untrusted); the
|
|
60
|
+
// fence's own refusal is expected. Same rules as Claude owner-native.
|
|
61
|
+
"-c",
|
|
62
|
+
`developer_instructions=${toml(`${input.instructions}\n\n${ownerRules(input.sharedRoom)}`)}`,
|
|
63
|
+
...codexHookArgs(hookPath),
|
|
64
|
+
...trustArgs,
|
|
65
|
+
...codexOwnerArgs({
|
|
66
|
+
catalogPath,
|
|
67
|
+
mcpArgs: mcp.args,
|
|
68
|
+
mcpCommand: mcp.command,
|
|
69
|
+
prompt: input.prompt,
|
|
70
|
+
sessionId: input.sessionId,
|
|
71
|
+
writableRoot: input.workspace.writeRoots[0] ?? input.workspace.cwd,
|
|
72
|
+
}),
|
|
73
|
+
];
|
|
74
|
+
return {
|
|
75
|
+
args,
|
|
76
|
+
cleanup: () => rm(jobDir, { force: true, recursive: true }),
|
|
77
|
+
jobDir,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/** A TOML basic string for a `-c key=value` override (value is model-visible text). */
|
|
81
|
+
function toml(value) {
|
|
82
|
+
return JSON.stringify(value);
|
|
83
|
+
}
|
|
84
|
+
function shellQuote(value) {
|
|
85
|
+
return `'${value.replaceAll("'", "'\\''")}'`;
|
|
86
|
+
}
|
|
@@ -13,13 +13,15 @@ import { codexHookArgs, trustHookArgs } from "./codex-owner.js";
|
|
|
13
13
|
// the hook AND its refusal held" (or, for the bypass classes, "the effect never
|
|
14
14
|
// happened"). Anything not proven is a failure: a Codex version that fails any
|
|
15
15
|
// cell stays room-only. Opt-in test: TALENTOS_TEST_CODEX.
|
|
16
|
-
export const CODEX_PROBE_REVISION =
|
|
16
|
+
export const CODEX_PROBE_REVISION = 2;
|
|
17
17
|
const RUN_MS = 25_000;
|
|
18
18
|
const MCP_NAME = /probe_mcp/u;
|
|
19
19
|
export const CODEX_CELLS = [
|
|
20
20
|
"trust",
|
|
21
21
|
"bash",
|
|
22
|
+
"bash_sandboxed",
|
|
22
23
|
"stdin",
|
|
24
|
+
"proc_fd",
|
|
23
25
|
"apply_patch",
|
|
24
26
|
"view_image",
|
|
25
27
|
"mcp_tool",
|
|
@@ -30,7 +32,8 @@ export const CODEX_CELLS = [
|
|
|
30
32
|
"repo_hooks_ignored",
|
|
31
33
|
];
|
|
32
34
|
// The hook our probe installs: records every call, allows only the opening
|
|
33
|
-
// `sh` of the stdin cell
|
|
35
|
+
// `sh` of the stdin cell (and the one command a cell names in PROBE_ALLOW),
|
|
36
|
+
// refuses everything else.
|
|
34
37
|
const HOOK = `#!/usr/bin/env node
|
|
35
38
|
let raw = "";
|
|
36
39
|
process.stdin.on("data", (c) => (raw += c));
|
|
@@ -39,6 +42,7 @@ process.stdin.on("end", () => {
|
|
|
39
42
|
require("node:fs").appendFileSync(process.env.PROBE_RECORDS, raw.replace(/\\n/g, " ") + "\\n");
|
|
40
43
|
const open =
|
|
41
44
|
(call.tool_name === "Bash" && call.tool_input?.command === "sh") ||
|
|
45
|
+
(call.tool_name === "Bash" && process.env.PROBE_ALLOW && call.tool_input?.command === process.env.PROBE_ALLOW) ||
|
|
42
46
|
call.tool_name === "collaborationspawn_agent";
|
|
43
47
|
process.stdout.write(JSON.stringify({ hookSpecificOutput: {
|
|
44
48
|
hookEventName: "PreToolUse",
|
|
@@ -85,6 +89,85 @@ function parentStep(turn) {
|
|
|
85
89
|
}
|
|
86
90
|
return message("done");
|
|
87
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* A Python script (argv[1] is the line to type) that walks up to the nearest
|
|
94
|
+
* `codex` ancestor and types the line into every pipe or pty master open in
|
|
95
|
+
* that process tree but its own, two ways: reopening `/proc/<pid>/fd/<n>`
|
|
96
|
+
* (non-blocking, so a pipe with no reader is skipped) and taking the fd itself
|
|
97
|
+
* with `pidfd_getfd` (434/438 on x86_64 and arm64). Writes what it reached to
|
|
98
|
+
* argv[2], the proof that it ran.
|
|
99
|
+
*/
|
|
100
|
+
export const INJECTOR = `import ctypes, os, sys
|
|
101
|
+
line = sys.argv[1].encode() + b"\\n"
|
|
102
|
+
libc = ctypes.CDLL(None, use_errno=True)
|
|
103
|
+
def stat(pid):
|
|
104
|
+
try:
|
|
105
|
+
text = open("/proc/%d/stat" % pid).read()
|
|
106
|
+
except OSError:
|
|
107
|
+
return None
|
|
108
|
+
close = text.rindex(")")
|
|
109
|
+
return text[text.index("(") + 1:close], int(text[close + 2:].split()[1])
|
|
110
|
+
def tree():
|
|
111
|
+
root, at = None, os.getpid()
|
|
112
|
+
while at > 1 and root is None:
|
|
113
|
+
info = stat(at)
|
|
114
|
+
if info is None:
|
|
115
|
+
break
|
|
116
|
+
if info[0].startswith("codex"):
|
|
117
|
+
root = at
|
|
118
|
+
at = info[1]
|
|
119
|
+
if root is None:
|
|
120
|
+
return []
|
|
121
|
+
out = []
|
|
122
|
+
for name in os.listdir("/proc"):
|
|
123
|
+
if not name.isdigit() or int(name) == os.getpid():
|
|
124
|
+
continue
|
|
125
|
+
at = int(name)
|
|
126
|
+
while at > 1 and at != root:
|
|
127
|
+
info = stat(at)
|
|
128
|
+
at = info[1] if info else 1
|
|
129
|
+
if at == root:
|
|
130
|
+
out.append(int(name))
|
|
131
|
+
return out
|
|
132
|
+
reopened = taken = 0
|
|
133
|
+
for pid in tree():
|
|
134
|
+
# Codex's own pipes carry its internal protocols; its pty masters are
|
|
135
|
+
# the session channel. Other processes: every pipe.
|
|
136
|
+
own = (stat(pid) or ("",))[0].startswith("codex")
|
|
137
|
+
try:
|
|
138
|
+
fds = os.listdir("/proc/%d/fd" % pid)
|
|
139
|
+
except OSError:
|
|
140
|
+
continue
|
|
141
|
+
pidfd = libc.syscall(434, pid, 0)
|
|
142
|
+
for fd in fds:
|
|
143
|
+
try:
|
|
144
|
+
target = os.readlink("/proc/%d/fd/%s" % (pid, fd))
|
|
145
|
+
except OSError:
|
|
146
|
+
continue
|
|
147
|
+
if not ("ptmx" in target or (target.startswith("pipe:") and not own)):
|
|
148
|
+
continue
|
|
149
|
+
if target.startswith("pipe:"):
|
|
150
|
+
try:
|
|
151
|
+
out = os.open("/proc/%d/fd/%s" % (pid, fd), os.O_WRONLY | os.O_NONBLOCK)
|
|
152
|
+
os.write(out, line)
|
|
153
|
+
os.close(out)
|
|
154
|
+
reopened += 1
|
|
155
|
+
except OSError:
|
|
156
|
+
pass
|
|
157
|
+
if pidfd >= 0:
|
|
158
|
+
got = libc.syscall(438, pidfd, int(fd), 0)
|
|
159
|
+
if got >= 0:
|
|
160
|
+
try:
|
|
161
|
+
os.set_blocking(got, False)
|
|
162
|
+
os.write(got, line)
|
|
163
|
+
taken += 1
|
|
164
|
+
except OSError:
|
|
165
|
+
pass
|
|
166
|
+
os.close(got)
|
|
167
|
+
import time
|
|
168
|
+
time.sleep(1)
|
|
169
|
+
open(sys.argv[2], "w").write("reopened %d taken %d" % (reopened, taken))
|
|
170
|
+
`;
|
|
88
171
|
async function runCell(binary, root, options, signal) {
|
|
89
172
|
const home = mkdtempSync(join(root, "home-"));
|
|
90
173
|
const work = mkdtempSync(join(root, "work-"));
|
|
@@ -103,7 +186,7 @@ async function runCell(binary, root, options, signal) {
|
|
|
103
186
|
let turn = 0;
|
|
104
187
|
let canaryUrl = "";
|
|
105
188
|
const scriptText = () => typeof options.script === "function"
|
|
106
|
-
? options.script(canaryUrl)
|
|
189
|
+
? options.script(canaryUrl, work)
|
|
107
190
|
: options.script;
|
|
108
191
|
const server = createServer(async (request, response) => {
|
|
109
192
|
let raw = "";
|
|
@@ -156,6 +239,7 @@ async function runCell(binary, root, options, signal) {
|
|
|
156
239
|
CODEX_HOME: home,
|
|
157
240
|
HOME: home,
|
|
158
241
|
PATH: process.env.PATH,
|
|
242
|
+
...(options.allow ? { PROBE_ALLOW: options.allow } : {}),
|
|
159
243
|
PROBE_RECORDS: records,
|
|
160
244
|
TALENTOS_PROBE_KEY: "loopback-only",
|
|
161
245
|
};
|
|
@@ -182,7 +266,13 @@ async function runCell(binary, root, options, signal) {
|
|
|
182
266
|
"-c",
|
|
183
267
|
'model_providers.talentos_probe.env_key="TALENTOS_PROBE_KEY"',
|
|
184
268
|
"-c",
|
|
185
|
-
|
|
269
|
+
`sandbox_mode="${options.sandbox ?? "danger-full-access"}"`,
|
|
270
|
+
// /tmp is writable under workspace-write by default; the probe root
|
|
271
|
+
// lives there, so keep it out for the sandbox control to mean anything.
|
|
272
|
+
"-c",
|
|
273
|
+
"sandbox_workspace_write.exclude_slash_tmp=true",
|
|
274
|
+
"-c",
|
|
275
|
+
"sandbox_workspace_write.exclude_tmpdir_env_var=true",
|
|
186
276
|
"-c",
|
|
187
277
|
`approval_policy="${options.approval ?? "never"}"`,
|
|
188
278
|
...hookArgs,
|
|
@@ -259,6 +349,36 @@ export async function probeCodexOwnerNative(binary, version, signal = AbortSigna
|
|
|
259
349
|
}
|
|
260
350
|
return true;
|
|
261
351
|
});
|
|
352
|
+
// The same deny under Codex's own OS sandbox (bubblewrap on Linux,
|
|
353
|
+
// Seatbelt on macOS): a sandbox is a backstop, never a reason to skip the
|
|
354
|
+
// hook. A host where the sandbox cannot start fails this cell.
|
|
355
|
+
await cell("bash_sandboxed", async () => {
|
|
356
|
+
for (const sandbox of ["workspace-write", "read-only"]) {
|
|
357
|
+
for (const approval of ["never", "on-request"]) {
|
|
358
|
+
const name = `sandboxed-${sandbox}-${approval}`;
|
|
359
|
+
const run = await runCell(binary, root, {
|
|
360
|
+
approval,
|
|
361
|
+
sandbox,
|
|
362
|
+
script: (_canary, work) => js(`await tools.exec_command({cmd: ${JSON.stringify(`echo x > ${join(work, name)}`)}});`),
|
|
363
|
+
}, signal);
|
|
364
|
+
if (seen(run, "Bash").length !== 1 ||
|
|
365
|
+
existsSync(join(run.work, name))) {
|
|
366
|
+
return false;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
// Control: the sandbox really runs here (an allowed write inside the
|
|
371
|
+
// workspace lands, one outside it does not).
|
|
372
|
+
const inside = "sandbox-control";
|
|
373
|
+
const outside = marker("sandbox-outside");
|
|
374
|
+
const command = `echo x > ${inside}; echo x > ${outside}`;
|
|
375
|
+
const run = await runCell(binary, root, {
|
|
376
|
+
allow: command,
|
|
377
|
+
sandbox: "workspace-write",
|
|
378
|
+
script: js(`await tools.exec_command({cmd: ${JSON.stringify(command)}});`),
|
|
379
|
+
}, signal);
|
|
380
|
+
return existsSync(join(run.work, inside)) && !existsSync(outside);
|
|
381
|
+
});
|
|
262
382
|
// R13 (1): an open exec session driven through write_stdin. The first `sh`
|
|
263
383
|
// is allowed; what the model then types into it must never run.
|
|
264
384
|
await cell("stdin", async () => {
|
|
@@ -269,6 +389,27 @@ if (r.session_id !== undefined) { await tools.write_stdin({session_id: r.session
|
|
|
269
389
|
}, signal);
|
|
270
390
|
return !existsSync(file);
|
|
271
391
|
});
|
|
392
|
+
// The ancestor-fd channel: a same-user child of an approved command takes
|
|
393
|
+
// the open session's input from the Codex process tree, by reopening
|
|
394
|
+
// /proc/<pid>/fd/* or with pidfd_getfd, and types a command into it. That
|
|
395
|
+
// command runs with no hook call. macOS has neither (the cell passes
|
|
396
|
+
// there because the channel does not exist); without python3 it fails.
|
|
397
|
+
await cell("proc_fd", async () => {
|
|
398
|
+
const file = marker("procfd");
|
|
399
|
+
const injector = join(root, "inject.py");
|
|
400
|
+
writeFileSync(injector, INJECTOR);
|
|
401
|
+
const ran = marker("procfd-ran");
|
|
402
|
+
const command = `python3 -I ${injector} ${JSON.stringify(`echo x > ${file}`)} ${ran}`;
|
|
403
|
+
const run = await runCell(binary, root, {
|
|
404
|
+
allow: command,
|
|
405
|
+
script: js(`await tools.exec_command({cmd: "sh", yield_time_ms: 300});
|
|
406
|
+
await tools.exec_command({cmd: "sh", tty: true, yield_time_ms: 300});
|
|
407
|
+
await tools.exec_command({cmd: ${JSON.stringify(command)}, yield_time_ms: 3000});`),
|
|
408
|
+
}, signal);
|
|
409
|
+
return (existsSync(ran) &&
|
|
410
|
+
!existsSync(file) &&
|
|
411
|
+
seen(run, "Bash").some((call) => call.tool_input?.command === command));
|
|
412
|
+
});
|
|
272
413
|
// R13 (2): the hook sees every path of a patch, renames and deletes too.
|
|
273
414
|
await cell("apply_patch", async () => {
|
|
274
415
|
const dir = join(root, "patch");
|