feat(tools): run provider-native code execution on the sandbox when the model has none, with Files API parity - #1366
Conversation
|
Understand this PR’s impact Explore downstream dependencies and potential security impact with Blast Radius. Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: mozilla-ai/otari/.coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (7)
🚧 Files skipped from review as they are similar to previous changes (5)
Included review availability: Your plan provides up to 2 included reviews per hour; 0 remain after this review. WalkthroughThis pull request adds configurable code-execution routing, sandbox file transfer, provider-held file support, cursor-paged file APIs, fsspec storage, retention sweeping, frontend controls, documentation, demos, and tests. ChangesCode execution and files
Priority: ➖ Normal Estimated code review effort: 5 (Critical) | ~90 minutes 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 36.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 501 functions across 55 files. (2 skipped: 2 unsupported.) ✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
dbb0d5d to
6eb79b6
Compare
The OpenAPI spec, the Postman collection built from it and the dashboard's generated client all follow the routes and schemas above. Three demos under `demo/code-exec` drive a running gateway with the Anthropic SDK, the OpenAI SDK and any-llm, each asking for a plot, which is what exercises the executor and the files round trip by hand. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
a81ed09 to
e7452c8
Compare
Description
A request that declares a provider's own code-execution tool (Anthropic's
code_execution_20250825, OpenAI'scode_interpreter, or the barecode_execution) is today always forwarded to the provider. Only the Otari-specificotari_code_executiontype reaches the gateway's sandbox. So a client built against Anthropic's sandbox breaks the moment its model is swapped for one without a native sandbox, and the files it attaches break with it.What changes. The gateway now decides who runs such a declaration, in three settings:
auto(the new default): the provider when it runs that tool natively for the dispatched model and wire format; otherwise the gateway's sandbox, answering in the caller's own vocabulary (server_tool_useandcode_execution_tool_resultblocks on Messages, acode_interpreter_callitem on Responses).otari: always the gateway's sandbox.provider: always forwarded, exactly as before.The deployment sets the default (
code_execution_executor, also on the dashboard's Tools page), a workspace policy may pin a value, and theX-Otari-Code-Executionheader picks per request where the workspace has not pinned. A deployment without a sandbox is untouched: provider declarations are forwarded and no policy is read.otari_code_executionkeeps working unchanged.Behavior change for a deployment that already has
sandbox_urlset. Under the new default, a provider-named declaration (code_interpreter,code_execution_<date>,code_execution) against a model whose provider does not run it natively used to be forwarded and refused upstream; it now runs on the deployment's sandbox and is billed as a sandbox tool call, andGET /api/v1/toolslists those keywords underotari_code_execution.accepted_types. Setcode_execution_executor: providerto keep the old behavior.The workspace policy is read once, in the request preamble, so the same decision says whether a referenced upload is staged for the sandbox and who runs the code; a pin can no longer leave a request without its attachments. A file a provider's own sandbox produced is recorded on the streaming path as well as the non-streaming one, through the pipeline's settlement rather than in each route, keyed to the configured provider instance that served the request.
Files follow the same rule. This absorbs and supersedes #1364 (Files API parity) and wires it to the executor:
FileMetadatafor a caller sendinganthropic-version, the OpenAI file object otherwise). Listings are cursor-paged, anfsspecstorage backend joinslocalands3, and a background sweep reclaims expired and deleted files.container_uploadis read as a document, as it is today.code_execution_outputfiles owned by the same user and workspace, at mostfiles_output_max_filesandfiles_output_max_bytesper call (20 files, 64 MB). An Anthropic-native caller gets theirfile_idin the result block, where its SDK looks.Follow-ups, not in this PR: a
CodeExecutionPortwith an e2b adapter, cross-request container ids, files in hybrid mode,cfile_ids on Responses, a platform-side executor pin in hybrid mode, a public any-llm capability flag to replace the private-attribute check that decides whichbetasa bridged provider can take (mozilla-ai/any-llm#1418), and an any-llm files API to replace the hand-rolled provider download inprovider_files.py(mozilla-ai/any-llm#1419). Thefsspecbackend ships as the optionalotari[fsspec]extra, likeotari[s3].How to test it locally
docker compose --profile code-exec up, then send an Anthropic Messages request withtools: [{"type": "code_execution_20250825", "name": "code_execution"}]against a non-Anthropic model. The code runs on the sandbox and the response carriesserver_tool_useandcode_execution_tool_resultblocks withotari_srvtoolu_ids.X-Otari-Code-Execution: otariand it runs here instead.GET /api/v1/files?limit=2pages withhas_moreandlast_id. Reference it from a request that runs on the sandbox: the file is in the session's working directory, and a file the run writes comes back as afile_idin the tool result.GET /api/v1/toolslists the provider keywords underotari_code_execution.accepted_typesunless the default isprovider.demo/code-exec/qa_executor.pywalks all four against a running gateway.Automated coverage:
tests/unit/test_code_executor.py(the decision and when attachments are staged),tests/integration/test_code_execution_executor.py(request path, header, pin, folding), native block minting intests/unit/test_mcp_loop_messages.pyandtests/unit/test_mcp_loop_responses.py, echoed-block folding intests/unit/test_messages_minted_block_stripping.py, the files tests (tests/integration/test_files_endpoint.py,tests/unit/test_sandbox_backend.py,tests/unit/test_content_normalizer.py,tests/unit/test_fsspec_file_store.py), plus the tool-settings, tools-discovery and dashboard tests.make lint,make typecheck, the unit and integration suites, the OSS smoke gate and the dashboard suite pass locally.PR Type
Relevant issues
Supersedes #1364 (and through it #976 and #977). Part of #786. Groundwork for the code-execution provider abstraction discussed alongside #896.
Checklist
tests/unit,tests/integration).make lint,make typecheck,make test).uv run python scripts/generate_openapi.py).ARCHITECTURE.mdorscripts/check_architecture.py, the description names the rule and says why.AI Usage
AI Model/Tool used: Claude Code (Claude Fable 5.1)
Any additional AI details you'd like to share: Design agreed with the maintainer in conversation. The executor half was implemented, tested and documented by the agent; the files half is the maintainer's #1364, merged in and adapted to the executor by the agent. Everything was verified locally.
🤖 Generated with Claude Code
Summary
auto,otari, andprovidermodes.Technical notes