Skip to content

Send sandbox state through MCP tool metadata#17763

Merged
aaronl-openai merged 4 commits intomainfrom
aaronl/codex-sandbox-mcp-state-meta
Apr 15, 2026
Merged

Send sandbox state through MCP tool metadata#17763
aaronl-openai merged 4 commits intomainfrom
aaronl/codex-sandbox-mcp-state-meta

Conversation

@aaronl-openai
Copy link
Copy Markdown
Collaborator

@aaronl-openai aaronl-openai commented Apr 14, 2026

Changes

Allows MCPs to opt in to receiving sandbox config info through _meta on model-initiated tool calls. This lets MCPs adhere to the thread's sandbox if they choose to.

Details

  • Adds the codex/sandbox-state-meta experimental MCP capability.
  • Tracks whether each MCP server advertises that capability.
  • When a server opts in, codex-core injects the current SandboxState into model-initiated MCP tool-call request _meta.

Verification

  • added an integration test for the capability

@aaronl-openai aaronl-openai requested a review from bolinfest April 14, 2026 14:56
Copy link
Copy Markdown
Collaborator

@bolinfest bolinfest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to have an integration test for this.

}
}

pub const MCP_SANDBOX_STATE_CAPABILITY: &str = "codex/sandbox-state";
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should get rid of this, but I'll do that in a follow-up PR.

/// Custom MCP request to push sandbox state updates.
/// When used, the `params` field of the notification is [`SandboxState`].
pub const MCP_SANDBOX_STATE_METHOD: &str = "codex/sandbox-state/update";
pub const MCP_SANDBOX_STATE_META_CAPABILITY: &str = "codex/sandbox-state-meta";
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a docstring to explain what this capability does?

@@ -646,6 +647,7 @@
/// Custom MCP request to push sandbox state updates.
/// When used, the `params` field of the notification is [`SandboxState`].
pub const MCP_SANDBOX_STATE_METHOD: &str = "codex/sandbox-state/update";
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should be able to remove this, as well.

return Ok(meta);
}

let sandbox_state = serde_json::to_value(SandboxState {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SandboxState was introduced before we introduced PermissionProfile:

#[derive(Debug, Clone, Default, Eq, Hash, PartialEq, Serialize, Deserialize, JsonSchema, TS)]
pub struct PermissionProfile {
pub network: Option<NetworkPermissions>,
pub file_system: Option<FileSystemPermissions>,
}

I think we should be passing that instead (and update codex sandbox to take it).

Also, I don't think you need codex_linux_sandbox_exe, though you likely want the path to codex itself?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one thing I'm concerned about is that it looks like FileSystemSandboxPolicy/NetworkSandboxPolicy are more expressive than PermissionProfile. for example, FileSystemSandboxPolicy can give readwrite access to /some/folder except readonly access to /some/folder/readonly/, which I don't think we can express with PermissionProfile.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, yes, I'll fix this up once I merge #15914

@aaronl-openai aaronl-openai merged commit 42528a9 into main Apr 15, 2026
41 of 47 checks passed
@aaronl-openai aaronl-openai deleted the aaronl/codex-sandbox-mcp-state-meta branch April 15, 2026 07:49
@github-actions github-actions bot locked and limited conversation to collaborators Apr 15, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants