Skip to content

unsloth run: add --enable-tools/--disable-tools server-side tool policy - #5277

Merged
rolandtannous merged 8 commits into
mainfrom
feature/run-enable-disable-tools
May 5, 2026
Merged

rolandtannous merged 8 commits into
mainfrom
feature/run-enable-disable-tools

Conversation

@rolandtannous

@rolandtannous rolandtannous commented May 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Adds --enable-tools/--disable-tools and --yes/-y flags to unsloth run. The resolved value becomes a process-level hard override applied at three gate sites in studio/backend/routes/inference.py: the OpenAI tools pass-through early-out, /chat/completions agentic loop, and Anthropic /messages server-side tools.
  • Defaults flip with the bind address: 127.0.0.1 defaults to tools-on (local-only, low risk), 0.0.0.0 defaults to tools-off; 0.0.0.0 + --enable-tools shows a y/N security prompt warning that an API-key leak means arbitrary code execution on the host. The prompt is skipped when --silent or --yes is passed.
  • The pure resolver lives in unsloth_cli/_tool_policy.py so 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.
  • Banner notice and confirmation prompt are styled in Claude orange so they stand out from surrounding banner text.

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-tools on 127.0.0.1 — banner shows "Server-side tools are disabled" in orange; tool-using chat request behaves as if enable_tools=false.
  • unsloth run --model ... --host 0.0.0.0 — banner shows the disabled-by-default notice; tool-using chat request behaves as if enable_tools=false even when the request body sets enable_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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread unsloth_cli/_tool_policy.py Resolved
Comment thread unsloth_cli/commands/studio.py Resolved
Comment thread unsloth_cli/_tool_policy.py Resolved
Comment thread unsloth_cli/commands/studio.py Resolved
@rolandtannous

rolandtannous commented May 5, 2026 •

Copy link
Copy Markdown
Contributor Author

tests:

Screenshot 2026-05-05 at 11 46 33 AM Screenshot 2026-05-05 at 12 10 19 PM Screenshot 2026-05-05 at 12 09 52 PM Screenshot 2026-05-05 at 11 48 10 AM Screenshot 2026-05-05 at 11 47 16 AM

policy enforced: cannot be superseded on aper call basis :
Screenshot 2026-05-05 at 12 35 27 PM

@rolandtannous

Copy link
Copy Markdown
Contributor Author

all comments resolved. tests passed successfully and shared. merging.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread unsloth_cli/_tool_policy.py Resolved
Calvinkev pushed a commit to Calvinkev/unslothcalvin that referenced this pull request Jun 14, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant