Repository navigation
Studio: API keys cannot approve host-path tool calls out of the sandbox - #14757
Conversation
/tool-confirm refuses an allow from an API-key or keyless caller for a parked call that would reach host paths, unless UNSLOTH_STUDIO_ALLOW_API_FULL_ACCESS=1. Deny stays open to everyone. On the launch side, a call from an API-key request ignores an approval and stays in the OS sandbox (required mode), whoever approved it. The tool thread now keeps the API-key flag for owner-scoped keys too.
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dfaad6d63a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| host_reach_approved = ( | ||
| host_access_approved | ||
| and _reaches_host_paths("terminal", command) | ||
| and not _api_host_access_refused() |
There was a problem hiding this comment.
Keep API-approved terminal calls in required isolation
When a UI session approves a host-path terminal call originating from an API key and the OS sandbox is unavailable or becomes stale, this expression clears host_reach_approved before _prepare_tool_launch sees it. The plan therefore remains auto, so prepare_tool_launch may fall back to software-safeguards and execute the command against the host filesystem; unlike the Python path, the new fail-closed conversion to required never runs. Preserve the approval signal until _prepare_tool_launch handles the API restriction, or explicitly switch requested_mode to required here.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Good catch, fixed. _bash_exec dropped an API-key request's approval before _prepare_tool_launch ran, so the terminal call stayed in auto and could fall back to software safeguards once the OS sandbox went away. The terminal now passes the approval through like the python path does, and _prepare_tool_launch drops it and moves the call to required, so a missing sandbox refuses instead of running on the host. The new test runs _bash_exec with an approved host-path command and a sandbox backend that has gone away. Before the fix the API-key case reached the backend in auto; now it is required and never falls back. A UI request still gets the software-safeguards launch its approval asks for.
The terminal dropped an API-key request's approval before _prepare_tool_launch, so the call stayed in auto and could fall back to software safeguards when the OS sandbox went away. It now passes the approval through like python, and _prepare_tool_launch drops it and moves the call to required. [skip ci]
|
Codex Review: Didn't find any major issues. Another round soon, please! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Problem
#14345 and #14422 set the rule that an API key (or keyless API access) never runs Python or Terminal without the OS sandbox unless the server sets
UNSLOTH_STUDIO_ALLOW_API_FULL_ACCESS=1: Full access,bypass_permissions,disable_sandboxandsandbox_level: "low"are all refused for API callers.The tool approval path was not part of that rule. In
autoandaskmodes a call that names a host path outside the sandbox roots parks for confirmation, and an approved one launches with software safeguards only (_prepare_tool_launch, faultuser_approved_host_access).POST /api/inference/tool-confirmaccepts an approval from any authenticated caller, API keys included, and the request that started the run receives the approval id in its own stream. So an API caller could approve its own parked host-path call and get the unsandboxed launch the other checks refuse.A second gap made the launch side unable to tell: for an owner-scoped API key,
account_tool_streamran the tool thread without rebinding the account, so the thread lost the "admitted by an API key" flag.Change
/tool-confirm: anallowfrom an API-key or keyless caller for a parked call that would reach host paths gets 403, naming the env opt-in.denyis accepted from everyone, and approving a call that stays in the sandbox is unchanged.studio_tool_loop,llama_cpp,safetensors_agentic) flag a parked call as host access when it is registered, using the same_reaches_host_pathscheck the executor applies before honouring an approval (approval_grants_host_access). The flag is set before the approval id is sent to the client._prepare_tool_launchignores an approval for a call that came from an API-key request and keeps it in the OS sandbox inrequiredmode, so a sandbox that is unavailable refuses instead of falling back to software safeguards. The Windows cmd Terminal path applies the same check.account_tool_streamnow rebinds the account for owner API-key requests too, so the tool thread sees the same API-key flag the request had (this also makes the existingrequire_tool_accesscheck insideexecute_tooleffective for owner keys).UNSLOTH_STUDIO_ALLOW_API_FULL_ACCESS=1restores the previous behaviour for API callers. Unsloth UI and Desktop sessions are unchanged.Tests
New
studio/backend/tests/test_api_key_tool_confirm.pydrives each of the three tool loops end to end with a real approval slot, the real/tool-confirmroute (API-key auth faked as intest_api_key_sandbox_level.py) and the real_prepare_tool_launchdecision (OS sandbox stubbed):requiredUNSLOTH_STUDIO_ALLOW_API_FULL_ACCESS=1askmode)14 of the 26 new tests fail on main and all 26 pass on this branch.
The 25 existing studio backend test files that touch tool approvals,
host_access_approved, the API Full access opt-in,sandbox_levelor_prepare_tool_launch, plus the new file (CPU, Linux): 4334 passed on this branch and 4320 on main. The same 36 tests fail on both: the MCP tests intest_account_tool_isolation.py, plus tests intest_llama_admission_compat_matrix.py,test_mcp_image.py,test_llama_cpp_tool_loop.py::test_web_search_keeps_to_the_requested_domainsand the Terminal cases oftest_tool_sandbox_wiring.py. The only other difference is the 14 new tests, which fail on main.Not covered
auto, approved or not. That is unchanged here, for API callers too.autofalls back to software safeguards for calls that never park. That is unchanged too. Only the approved host-path call from an API key is now refused.