Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

fix: force uv as the set package manager when running --sandbox (#3925)

Myles Scolnick1001d83fc885
diff --git a/marimo/_server/start.py b/marimo/_server/start.py
index 4c1003dde1..e86ead9e2f 100644
--- a/marimo/_server/start.py
+++ b/marimo/_server/start.py
@@ -9,6 +9,7 @@ import uvicorn
import marimo._server.api.lifespans as lifespans
from marimo._config.manager import get_default_config_manager
+from marimo._config.settings import GlobalSettings
from marimo._runtime.requests import SerializedCLIArgs
from marimo._server.file_router import AppFileRouter
from marimo._server.main import create_starlette_app
@@ -118,6 +119,18 @@ def start(
)
LOGGER.info("Watch mode enabled, auto-save is disabled")
+ if GlobalSettings.MANAGE_SCRIPT_METADATA:
+ config_reader = config_reader.with_overrides(
+ {
+ # Currently, only uv is supported for managing script metadata
+ # If this changes, instead we should only update the config
+ # if the user's package manager does not support sandboxes.
+ "package_management": {
+ "manager": "uv",
+ }
+ }
+ )
+
session_manager = SessionManager(
file_router=file_router,
mode=mode,
diff --git a/tests/_cli/test_cli.py b/tests/_cli/test_cli.py
index 697a507050..4406619554 100644
--- a/tests/_cli/test_cli.py
+++ b/tests/_cli/test_cli.py
@@ -31,6 +31,7 @@ from marimo._utils.toml import read_toml
if TYPE_CHECKING:
from collections.abc import Generator, Iterator
+ from pathlib import Path
HAS_UV = DependencyManager.which("uv")
@@ -805,6 +806,51 @@ def test_cli_run_sandbox_prompt_yes() -> None:
p.kill()
[email protected](not HAS_UV, reason="uv is required for sandbox tests")
+def test_cli_new_with_custom_pyproject_config(tmp_path: Path) -> None:
+ # Create a custom pyproject.toml with special marimo config
+ pyproject_path = tmp_path / "pyproject.toml"
+ pyproject_content = """
+ [tool.marimo]
+ formatting = {line_length = 111}
+
+ [tool.marimo.runtime]
+ auto_instantiate = false
+
+ [tool.marimo.package_management]
+ manager = "pip"
+ """
+ pyproject_path.write_text(pyproject_content)
+
+ # Run with --sandbox to ensure the file is run in a sandbox
+ port = _get_port()
+ print(f"Running marimo edit with port {port}")
+ p = subprocess.Popen(
+ [
+ "marimo",
+ "edit",
+ "--sandbox",
+ "-p",
+ str(port),
+ "--headless",
+ "--no-token",
+ ],
+ cwd=tmp_path, # Run from the directory with pyproject.toml
+ )
+
+ try:
+ contents = _try_fetch(port)
+ assert contents is not None
+
+ # Verify that the custom config is applied
+ assert b'"line_length": 111' in contents
+ assert b'"auto_instantiate": false' in contents
+ # Verify that the package manager is switch to uv because we are running in a sandbox
+ assert b'"manager": "uv"' in contents
+ finally:
+ p.kill()
+
+
# shell-completion has 1 input (value of $SHELL) & 3 outputs (return code, stdout, & stderr)
# parameterize to give coverage. We use a boolean to specify if output on that stream should be present.
@pytest.mark.parametrize(