Skip to content

Commit c9cbeae

Browse files
committed
fix(server): Codex children no longer fail to start under a managed sandbox policy
Codex can be locked down by managed requirements (requirements.toml or MDM). When those forbid the danger-full-access sandbox, a Codex child delegated from a full-access parent inherits full-access, and Codex refuses the turn with "invalid value for sandbox_mode". T3 never asked Codex which modes it allows, so it reported every runtime mode as supported. The provider probe now reads configRequirements/read and reports only the runtime modes whose sandbox mode and approval policy the requirements allow. The existing runtime-mode resolution then steps an inherited mode down to the broadest allowed one, and an explicit request for a forbidden mode gets a clear error instead of a failed turn. With no requirements configured, nothing changes. Done with Claude Opus 5.5 in Claude Code, inside T3 Code.
1 parent 9e85538 commit c9cbeae

3 files changed

Lines changed: 101 additions & 2 deletions

File tree

‎apps/server/src/provider/CodexProvider.ts‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import type {
2626
ProviderOptionDescriptor,
2727
ServerProviderModel,
2828
ServerProviderSkill,
29+
RuntimeMode,
2930
} from "@t3tools/contracts";
3031
import { PREFERRED_DEFAULT_CODEX_MODELS, ServerSettingsError } from "@t3tools/contracts";
3132

@@ -36,6 +37,7 @@ import {
3637
} from "@t3tools/shared/model";
3738
import { resolveSpawnCommand } from "@t3tools/shared/shell";
3839
import { codexAppServerArgs, resolveCodexLaunchArgs } from "./codexLaunchArgs.ts";
40+
import { codexRuntimeModesAllowedByRequirements } from "./codexRuntimeModeRequirements.ts";
3941
import {
4042
buildServerProvider,
4143
COMPACT_SLASH_COMMAND,
@@ -93,6 +95,7 @@ export interface CodexAppServerProviderSnapshot {
9395
readonly version: string | undefined;
9496
readonly models: ReadonlyArray<ServerProviderModel> | undefined;
9597
readonly serviceTier?: string | undefined;
98+
readonly supportedRuntimeModes?: ReadonlyArray<RuntimeMode> | undefined;
9699
readonly skills: ReadonlyArray<ServerProviderSkill>;
97100
}
98101

@@ -551,7 +554,7 @@ const probeCodexAppServerProvider = Effect.fn("probeCodexAppServerProvider")(fun
551554

552555
// Optional discovery must finish before the outer timeout can discard the account result.
553556
const deadlineMs = spawnedAtMs + CODEX_AUTH_PROBE_TIMEOUT_MS - CODEX_DISCOVERY_MARGIN_MS;
554-
const [skillsResponse, models, serviceTier, rateLimits] = yield* Effect.all(
557+
const [skillsResponse, models, serviceTier, rateLimits, runtimeModes] = yield* Effect.all(
555558
[
556559
withCodexDiscoveryDeadline(client.request("skills/list", { cwds: [input.cwd] }), deadlineMs),
557560
accountResponse.account?.type === "chatgpt"
@@ -597,6 +600,18 @@ const probeCodexAppServerProvider = Effect.fn("probeCodexAppServerProvider")(fun
597600
),
598601
),
599602
),
603+
// Managed requirements can forbid a sandbox mode, and Codex then refuses
604+
// to start the turn, so delegation has to know which modes are allowed.
605+
withCodexDiscoveryDeadline(
606+
client.request("configRequirements/read", undefined),
607+
deadlineMs,
608+
CODEX_CONFIG_PROBE_TIMEOUT_MS,
609+
).pipe(
610+
Effect.map((response) => codexRuntimeModesAllowedByRequirements(response?.requirements)),
611+
Effect.catch(() =>
612+
Effect.logDebug("Codex config requirements read failed.").pipe(Effect.as(undefined)),
613+
),
614+
),
600615
],
601616
{ concurrency: "unbounded" },
602617
);
@@ -607,6 +622,7 @@ const probeCodexAppServerProvider = Effect.fn("probeCodexAppServerProvider")(fun
607622
version,
608623
models,
609624
serviceTier,
625+
supportedRuntimeModes: runtimeModes,
610626
skills: skillsResponse ? parseCodexSkillsListResponse(skillsResponse, input.cwd) : [],
611627
} satisfies CodexAppServerProviderSnapshot;
612628
});
@@ -860,7 +876,12 @@ export const checkCodexProviderStatus = Effect.fn("checkCodexProviderStatus")(fu
860876
});
861877

862878
return buildServerProvider({
863-
presentation: CODEX_PRESENTATION,
879+
presentation: {
880+
...CODEX_PRESENTATION,
881+
...(snapshot.supportedRuntimeModes
882+
? { supportedRuntimeModes: snapshot.supportedRuntimeModes }
883+
: {}),
884+
},
864885
enabled: codexSettings.enabled,
865886
checkedAt,
866887
models: pipe(
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import * as NodeAssert from "node:assert/strict";
2+
3+
import { describe, it } from "vite-plus/test";
4+
5+
import { codexRuntimeModesAllowedByRequirements } from "./codexRuntimeModeRequirements.ts";
6+
7+
describe("codexRuntimeModesAllowedByRequirements", () => {
8+
it("leaves every mode available when nothing restricts Codex", () => {
9+
NodeAssert.equal(codexRuntimeModesAllowedByRequirements(null), undefined);
10+
NodeAssert.equal(codexRuntimeModesAllowedByRequirements({}), undefined);
11+
});
12+
13+
it("drops full access when managed requirements forbid the danger-full-access sandbox", () => {
14+
NodeAssert.deepStrictEqual(
15+
codexRuntimeModesAllowedByRequirements({
16+
allowedSandboxModes: ["read-only", "workspace-write"],
17+
}),
18+
["approval-required", "auto-accept-edits", "auto"],
19+
);
20+
});
21+
22+
it("drops modes whose approval policy is forbidden", () => {
23+
NodeAssert.deepStrictEqual(
24+
codexRuntimeModesAllowedByRequirements({
25+
allowedApprovalPolicies: ["untrusted", "on-request"],
26+
}),
27+
["approval-required", "auto-accept-edits", "auto"],
28+
);
29+
NodeAssert.deepStrictEqual(
30+
codexRuntimeModesAllowedByRequirements({
31+
allowedSandboxModes: ["read-only", "workspace-write", "danger-full-access"],
32+
allowedApprovalPolicies: ["untrusted"],
33+
}),
34+
["approval-required"],
35+
);
36+
});
37+
});
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import type { RuntimeMode } from "@t3tools/contracts";
2+
import type * as CodexSchema from "effect-codex-app-server/schema";
3+
4+
type CodexRequirements = NonNullable<CodexSchema.V2ConfigRequirementsReadResponse["requirements"]>;
5+
6+
// Mirrors codexRuntimeModeTurnDefaults in CodexAdapterV2, which can't be
7+
// imported here because the adapter already imports this provider.
8+
const CODEX_RUNTIME_MODE_POLICIES: ReadonlyArray<{
9+
readonly runtimeMode: RuntimeMode;
10+
readonly sandboxMode: CodexSchema.V2ConfigRequirementsReadResponse__SandboxMode;
11+
readonly approvalPolicy: "untrusted" | "on-request" | "never";
12+
}> = [
13+
{ runtimeMode: "approval-required", sandboxMode: "read-only", approvalPolicy: "untrusted" },
14+
{
15+
runtimeMode: "auto-accept-edits",
16+
sandboxMode: "workspace-write",
17+
approvalPolicy: "on-request",
18+
},
19+
{ runtimeMode: "auto", sandboxMode: "workspace-write", approvalPolicy: "on-request" },
20+
{ runtimeMode: "full-access", sandboxMode: "danger-full-access", approvalPolicy: "never" },
21+
];
22+
23+
/**
24+
* The runtime modes Codex accepts under its managed requirements
25+
* (requirements.toml or MDM). Undefined when nothing restricts them, so every
26+
* mode stays available.
27+
*/
28+
export function codexRuntimeModesAllowedByRequirements(
29+
requirements: CodexRequirements | null | undefined,
30+
): ReadonlyArray<RuntimeMode> | undefined {
31+
const allowedSandboxModes = requirements?.allowedSandboxModes ?? undefined;
32+
const allowedApprovalPolicies = requirements?.allowedApprovalPolicies ?? undefined;
33+
if (allowedSandboxModes === undefined && allowedApprovalPolicies === undefined) {
34+
return undefined;
35+
}
36+
return CODEX_RUNTIME_MODE_POLICIES.filter(
37+
({ sandboxMode, approvalPolicy }) =>
38+
(allowedSandboxModes === undefined || allowedSandboxModes.includes(sandboxMode)) &&
39+
(allowedApprovalPolicies === undefined || allowedApprovalPolicies.includes(approvalPolicy)),
40+
).map(({ runtimeMode }) => runtimeMode);
41+
}

0 commit comments

Comments
 (0)