Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion baseten/sandbox/_fs.py

@cretz cretz Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hi, just noticed this draft PR. Let me know if this is something you are hitting and when it is ready for review.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Not in production. I found it while reading the copy code: a source path starting with - gets parsed by cp as an option. It's ready for review now, thanks for taking a look.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

To confirm, you are not a Baseten user hitting this issue at this time? Or is this just from a scan and you aren't using this code yourself?

This also exists in other SDKs and in Blaxel at https://github.com/blaxel-ai/sdk-python/blob/e9b63fd6bf8eabd02c451510a733e29615644fbf/src/blaxel/core/sandbox/sync/filesystem.py#L175 and in other places. I want to confirm impact.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Right, I'm not a Baseten user and haven't hit this myself. I found it while reading through sandbox SDK code, so it comes from a review, not a bug report. The impact is small: it only affects a relative path that starts with -, since absolute paths always start with /. If that isn't worth a change on your side, I'm fine with closing it.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is less of a concern at this time. I do think we'll close it and when we tackle, we can do it across all 3 SDKs.

Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,8 @@ def _copy_command(source: str, destination: str) -> str:
quoted = [
"'" + value.replace("'", "'\\''") + "'" for value in (source, destination)
]
return f"cp -r {quoted[0]} {quoted[1]}"
# End option parsing so relative paths beginning with - remain operands.
return f"cp -r -- {quoted[0]} {quoted[1]}"


def _watch_path(path: str, recursive: bool | None) -> str:
Expand Down
49 changes: 49 additions & 0 deletions tests/sandbox/test_copy_paths.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from __future__ import annotations

import subprocess
from pathlib import Path

import httpx
import pytest

from tests.sandbox.test_fs import _body, _Fake, _ok, _process


@pytest.mark.parametrize("asynchronous", [False, True])
@pytest.mark.parametrize(
("source", "destination"),
[("-source", "copy"), ("source", "-destination"), ("-source", "-destination")],
)
@pytest.mark.asyncio
async def test_copy_preserves_paths_starting_with_dash(
tmp_path: Path, source: str, destination: str, asynchronous: bool
) -> None:
(tmp_path / source).write_text("file contents")

def handle(request: httpx.Request) -> httpx.Response:
if request.method == "POST":
# Execute the SDK's actual command against local fixture files.
result = subprocess.run(
_body(request)["command"],
shell=True,
check=False,
cwd=tmp_path,
capture_output=True,
text=True,
timeout=5,
)
return _ok(
_process(
status="completed" if result.returncode == 0 else "failed",
exitCode=result.returncode,
stderr=result.stderr,
)
)
return _ok(_process())

fake = _Fake(handle)
if asynchronous:
await fake.async_sandbox().fs.copy(source=source, destination=destination)
else:
fake.sandbox().fs.copy(source=source, destination=destination)
assert (tmp_path / destination).read_text() == "file contents"
4 changes: 3 additions & 1 deletion tests/sandbox/test_fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,9 @@ def handle(request: httpx.Request) -> httpx.Response:

fake = _Fake(handle)
fake.sandbox().fs.copy(source="/tmp/it's", destination="/tmp/b c")
assert _body(fake.requests[0])["command"] == "cp -r '/tmp/it'\\''s' '/tmp/b c'"
assert (
_body(fake.requests[0])["command"] == "cp -r -- '/tmp/it'\\''s' '/tmp/b c'"
)
assert _path(fake.requests[1]) == "/process/7"

@pytest.mark.parametrize(
Expand Down
Loading