[codex] Add friendly Python SDK sandbox presets#24772
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The Python SDK currently exposes sandbox selection differently depending on where it is used: thread lifecycle methods accept
SandboxMode, while turns accept the lower-levelSandboxPolicyshape. For the common case of choosing an access level, that leaks app-server wire details into otherwise straightforward SDK usage.This makes the common path explicit and discoverable: callers choose a named sandbox preset once, using the same keyword on threads and turns. The preset name
workspace_writealso makes the granted capability clear at the callsite.What changed
Sandboxenum with documented presets:Sandbox.read_only: read files without allowing writes.Sandbox.workspace_write: the normal default for projects with a recorded trust decision; read files and write inside the workspace and configured writable roots.Sandbox.full_access: run without filesystem access restrictions.sandbox=delegates to app-server's configured default, while explicit turn overrides remain sticky for subsequent turns.sandbox=Sandbox..., translating to the existing app-server thread and turn representations internally.API impact
High-level turn calls now use
sandbox=instead ofsandbox_policy=:thread_start(...)already defaults toApprovalMode.auto_review, so normal writable usage is concise:With that combination, edits inside
cwdand configured writable roots run within the workspace-write sandbox. Operations that require approval, such as edits outside those roots, are routed through auto review. Whensandbox=is omitted, app-server resolves its configured default. A sandbox supplied torun(...)orturn(...)applies to that turn and subsequent turns.Test coverage
sdk/python/tests/test_public_api_signatures.pycovers the public export and parameter names, including the default approval mode.sdk/python/tests/test_public_api_runtime_behavior.pycovers preset mappings to the existing wire types and raw string rejection.