Repository navigation
unsloth run: add --enable-tools/--disable-tools server-side tool policy - #5277
Conversation
…ass-through gates
There was a problem hiding this comment.
Code Review
This pull request introduces a process-level tool policy for Unsloth Studio, allowing users to force server-side tools on or off via CLI flags (--enable-tools/--disable-tools). It implements a resolver that defaults tools to 'on' for localhost and 'off' for external hosts (0.0.0.0), requiring a security confirmation for the latter. The changes include a new state management module, a CLI resolver with unit tests, and updates to the inference routes to respect the global policy. Feedback focuses on improving security by treating all non-loopback addresses as external, ensuring the confirmation prompt is generic, and correctly forwarding the resolved policy to child processes to avoid redundant prompts.
|
all comments resolved. tests passed successfully and shared. merging. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dd5a286182
ℹ️ 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".
…cy (unslothai#5277) * Add process-level tool_policy state for unsloth run * Apply tool_policy override at chat/completions, /messages, and tool pass-through gates * Add pure resolver for unsloth run --enable-tools/--disable-tools * Wire --enable-tools/--disable-tools into unsloth run * Color tool-policy notices and confirmation prompt in Claude orange * Always show tool-status notice; print URL + API key in silent mode * Treat any non-loopback bind as external; forward --yes after parent prompt * Fix tool_policy double-module bug: import via state.tool_policy to share global with routes






Summary
--enable-tools/--disable-toolsand--yes/-yflags tounsloth run. The resolved value becomes a process-level hard override applied at three gate sites instudio/backend/routes/inference.py: the OpenAI tools pass-through early-out,/chat/completionsagentic loop, and Anthropic/messagesserver-side tools.127.0.0.1defaults to tools-on (local-only, low risk),0.0.0.0defaults to tools-off;0.0.0.0 + --enable-toolsshows a y/N security prompt warning that an API-key leak means arbitrary code execution on the host. The prompt is skipped when--silentor--yesis passed.unsloth_cli/_tool_policy.pyso the truth table is unit-testable without spinning up Typer or the studio venv. The y/N prompt runs in the outer process so the venv re-exec'd child never re-prompts.Test plan
unsloth run --model <localhost-default>— banner shows "Server-side tools are enabled by default for localhost" in orange; tool-using chat request succeeds.unsloth run --model ... --disable-toolson127.0.0.1— banner shows "Server-side tools are disabled" in orange; tool-using chat request behaves as ifenable_tools=false.unsloth run --model ... --host 0.0.0.0— banner shows the disabled-by-default notice; tool-using chat request behaves as ifenable_tools=falseeven when the request body setsenable_tools=true.unsloth run --model ... --host 0.0.0.0 --enable-tools— y/N prompt appears in orange; "n" exits with code 1; "y" continues and tool calls work.unsloth run --model ... --host 0.0.0.0 --enable-tools --yes— no prompt; tools enabled.unsloth run --model ... --host 0.0.0.0 --enable-tools --silent— no prompt, no banner; tools enabled.