codex - 💡(How to fix) Fix Capability-Scoped Script Access for Codex [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openai/codex#18831Fetched 2026-04-22 07:51:55
View on GitHub
Comments
0
Participants
1
Timeline
8
Reactions
0
Participants
Timeline (top)
labeled ×5unlabeled ×3

Fix Action

Fix / Workaround

for path in session.glob("src/**/*.ts"): before = session.read(path) patch = make_patch(before)

if patch: reply = session.checkpoint(f"Apply patch to {path}?", patch.summary) if reply.approve: session.tool("apply_patch", { "path": path, "patch": patch.text, })


- All child activity should be auditable in-session, including MCP invocations.
- Capabilities should be explicit: MCP/tool access, file read/write, patch, memory, network, sub-agents, call limits, expiry.
- Sensitive actions should still be able to require checkpoint approval.
- Cancellation should revoke the token and stop the child cleanly.
- Re-entrancy rules should prevent recursive agent/script deadlocks.

Code Example

# Codex writes this script, grants it a scoped token,
# and starts it with CODEX_CHANNEL + CODEX_TOKEN in env.
session = codex.connect(
    channel=os.environ["CODEX_CHANNEL"],
    token=os.environ["CODEX_TOKEN"],
)

for page in range(0, 3):
    rows = session.tool("mcp.Entity_List", {
        "from": page * 50,
        "pageSize": 50,
    })

    if suspicious(rows):
        reply = session.checkpoint("Investigate these rows?", rows[:5])
        if reply.approve:
            session.tool("mcp.Entity_Get", {"id": reply.id})

---

# Codex generates and runs this helper against the active session.
session = codex.connect(
    channel=os.environ["CODEX_CHANNEL"],
    token=os.environ["CODEX_TOKEN"],
)

for path in session.glob("src/**/*.ts"):
    before = session.read(path)
    patch = make_patch(before)

    if patch:
        reply = session.checkpoint(f"Apply patch to {path}?", patch.summary)
        if reply.approve:
            session.tool("apply_patch", {
                "path": path,
                "patch": patch.text,
            })

---

session = codex.connect(
    channel=os.environ["CODEX_CHANNEL"],
    token=os.environ["CODEX_TOKEN"],
)

users = session.tool("mcp.Entity_List", {"entityType": "User"})
schedules = session.tool("mcp.Entity_List", {"entityType": "Schedule"})

orphans = find_orphans(users, schedules)
session.summarize("Orphaned users", orphans[:20])
RAW_BUFFERClick to expand / collapse

What variant of Codex are you using?

CLI

What feature would you like to see?

Proposal: Capability-Scoped Script Access for Codex

Concept

Codex should let an agent-spawned script talk back to the active session through a short-lived, capability-scoped channel.

This would let the script invoke approved tools, including MCP tool calls specifically, pause for agent judgment at checkpoints, then resume. The goal is to let Codex generate and run task-specific helper scripts without routing every intermediate action through the main transcript/context.

Today, external scripts and session tools are separate tracks. A script can do local work, but it cannot use the active session's MCP tools or hand control back to the agent mid-execution. That makes workflows like pagination, reconciliation, and repetitive checkpointed edits much more expensive in context than they need to be.

Why

  • Reduces context bloat for loops, paging, joins, and bulk edits.
  • Enables script-driven workflows with agent checkpoints.
  • Lets Codex use MCP tools from inside a task-specific script instead of bouncing every call through the transcript.
  • Preserves agent judgment for the points that matter while keeping bulk execution local.

MVP

  1. codex session grant mints a short-lived token with explicit capabilities.
  2. codex.connect(...) binds a script to the active session channel.
  3. session.tool(...) lets the script call approved tools, including MCP tools exposed in the active session.
  4. session.checkpoint(...) sends a structured question/result back to the agent and waits for a reply.
  5. session.summarize(...) promotes selected output into transcript/context.

Examples

Small MCP pagination loop

# Codex writes this script, grants it a scoped token,
# and starts it with CODEX_CHANNEL + CODEX_TOKEN in env.
session = codex.connect(
    channel=os.environ["CODEX_CHANNEL"],
    token=os.environ["CODEX_TOKEN"],
)

for page in range(0, 3):
    rows = session.tool("mcp.Entity_List", {
        "from": page * 50,
        "pageSize": 50,
    })

    if suspicious(rows):
        reply = session.checkpoint("Investigate these rows?", rows[:5])
        if reply.approve:
            session.tool("mcp.Entity_Get", {"id": reply.id})

Small refactor with checkpointed apply

# Codex generates and runs this helper against the active session.
session = codex.connect(
    channel=os.environ["CODEX_CHANNEL"],
    token=os.environ["CODEX_TOKEN"],
)

for path in session.glob("src/**/*.ts"):
    before = session.read(path)
    patch = make_patch(before)

    if patch:
        reply = session.checkpoint(f"Apply patch to {path}?", patch.summary)
        if reply.approve:
            session.tool("apply_patch", {
                "path": path,
                "patch": patch.text,
            })

Cross-source MCP reconciliation

session = codex.connect(
    channel=os.environ["CODEX_CHANNEL"],
    token=os.environ["CODEX_TOKEN"],
)

users = session.tool("mcp.Entity_List", {"entityType": "User"})
schedules = session.tool("mcp.Entity_List", {"entityType": "Schedule"})

orphans = find_orphans(users, schedules)
session.summarize("Orphaned users", orphans[:20])

Required Guardrails

  • All child activity should be auditable in-session, including MCP invocations.
  • Capabilities should be explicit: MCP/tool access, file read/write, patch, memory, network, sub-agents, call limits, expiry.
  • Sensitive actions should still be able to require checkpoint approval.
  • Cancellation should revoke the token and stop the child cleanly.
  • Re-entrancy rules should prevent recursive agent/script deadlocks.

Core Principle

Scripts should act as scoped executors for the current session, not hidden parallel agents.

Additional information

No response

extent analysis

TL;DR

To implement capability-scoped script access for Codex, introduce a short-lived token system with explicit capabilities for scripts to interact with the active session.

Guidance

  • Introduce a codex session grant command to mint a short-lived token with explicit capabilities for scripts.
  • Implement codex.connect to bind a script to the active session channel using the granted token.
  • Develop session.tool to allow scripts to call approved tools, including MCP tools, within the active session.
  • Create session.checkpoint to enable scripts to send structured questions/results back to the agent and wait for a reply.
  • Establish session.summarize to promote selected output into the transcript/context.

Example

session = codex.connect(
    channel=os.environ["CODEX_CHANNEL"],
    token=os.environ["CODEX_TOKEN"],
)
rows = session.tool("mcp.Entity_List", {
    "from": 0,
    "pageSize": 50,
})

Notes

The proposed solution requires careful consideration of guardrails, including auditable child activity, explicit capabilities, and cancellation mechanisms to prevent security vulnerabilities and ensure seamless integration with the active session.

Recommendation

Apply the proposed workaround by introducing the short-lived token system and implementing the necessary session management functions to enable capability-scoped script access for Codex. This approach allows for more efficient and secure script execution while maintaining agent judgment and control.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

codex - 💡(How to fix) Fix Capability-Scoped Script Access for Codex [1 participants]