Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: auto-start the server from the same install as unsloth start (#16948)

Nilay6106dfc69e77
diff --git a/tests/studio/test_cli_start_launcher.py b/tests/studio/test_cli_start_launcher.py
new file mode 100644
index 00000000000..cdbf9519475
--- /dev/null
+++ b/tests/studio/test_cli_start_launcher.py
@@ -0,0 +1,43 @@
+# SPDX-License-Identifier: AGPL-3.0-only
+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+from __future__ import annotations
+
+import os
+import sys
+import tempfile
+from pathlib import Path
+
+import pytest
+
+import unsloth_cli.commands.start as start_cli
+
+
+class Spawned(Exception):
+ pass
+
+
+def test_auto_started_server_runs_on_this_interpreter_without_unsloth_on_path(
+ monkeypatch, tmp_path
+):
+ commands = []
+
+ def popen(command, **kwargs):
+ commands.append(command)
+ raise Spawned
+
+ monkeypatch.setenv("PATH", str(tmp_path))
+ monkeypatch.setattr(start_cli.subprocess, "Popen", popen)
+ try:
+ with pytest.raises(Spawned):
+ start_cli._start_studio_server(
+ "http://127.0.0.1:8888", "unsloth/Qwen3-0.6B-GGUF", start_cli.LoadOptions()
+ )
+ finally:
+ (Path(tempfile.gettempdir()) / f"unsloth-start-server-{os.getpid()}.log").unlink(
+ missing_ok = True
+ )
+
+ command = commands[0]
+ assert command[0] == sys.executable
+ assert command[command.index("-c") + 2] == "run"
diff --git a/unsloth_cli/commands/start.py b/unsloth_cli/commands/start.py
index 2b9571956ff..e6b1c029fc8 100644
--- a/unsloth_cli/commands/start.py
+++ b/unsloth_cli/commands/start.py
@@ -1471,13 +1471,11 @@ def _start_studio_server(
) -> tuple:
"""Spawn `unsloth run` for `model`, wait until it is fully ready, and return (base, server)."""
global _auto_served_server
- # Windows goes through this interpreter, not the launcher on PATH: shutil.which resolves `unsloth` to the denied unsloth.exe, since PATHEXT puts .EXE ahead of the .cmd shim (#8490). Without this, a user who reached the CLI through unsloth.cmd would still fail here. sys.executable is the interpreter already running this command, so the child inherits the same environment.
- if sys.platform == "win32":
- # Local import: unsloth_cli.commands.studio imports at package init after this module, so a top-level import would be circular.
- from unsloth_cli.commands.studio import _managed_cli_argv
- launch_head = _managed_cli_argv(Path(sys.executable))
- else:
- launch_head = [shutil.which("unsloth") or "unsloth"]
+ # This interpreter, not the `unsloth` on PATH: that can be missing, another install, or on Windows the denied unsloth.exe (#8490).
+ # Local import: unsloth_cli.commands.studio imports at package init after this module, so a top-level import would be circular.
+ from unsloth_cli.commands.studio import _managed_cli_argv
+
+ launch_head = _managed_cli_argv(Path(sys.executable))
parsed = urlparse(base)
# Tools default off means passthrough mode (relay the agent's own tools); --no-cloudflare means loopback only, no tunnel. Mirrors .github/scripts/serve-unsloth-run.sh. Healing/nudging travel via the child env below (version-agnostic) rather than new run flags that an older re-exec'd run could mistake for llama-server args.
command = [
diff --git a/unsloth_cli/tests/test_start.py b/unsloth_cli/tests/test_start.py
index fdbe8686d2a..c865167c29c 100644
--- a/unsloth_cli/tests/test_start.py
+++ b/unsloth_cli/tests/test_start.py
@@ -5159,8 +5159,8 @@ def test_start_studio_server_builds_command_and_waits(monkeypatch, capsys):
),
)
cmd = captured["command"]
- # Windows launches through this interpreter (`python -X utf8 ...`), so "run" follows a longer head.
- assert cmd[1 if os.name != "nt" else cmd.index("run")] == "run"
+ assert cmd[0] == sys.executable
+ assert cmd[cmd.index("-c") + 2] == "run"
assert "--disable-tools" in cmd and "--no-cloudflare" in cmd
assert "--reasoning" not in cmd
assert captured["kwargs"]["env"]["LLAMA_ARG_REASONING"] == "auto"