Skip to content

Commit 263967b

Browse files
ampagentIsaac Miller
andcommitted
Handle aliased mount collisions
Amp-Thread-ID: https://ampcode.com/threads/T-019fcce1-bc8b-753e-886f-9b77c0ccb376 Co-authored-by: Isaac Miller <isaac@cmpnd.ai>
1 parent 3df6c09 commit 263967b

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

‎dspy/primitives/python_interpreter.py‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,13 +267,14 @@ def __init__(
267267

268268
self.enable_read_paths = enable_read_paths or []
269269
self.enable_write_paths = enable_write_paths or []
270-
mounts = {
271-
_canonicalize_path(path): os.path.basename(os.fspath(path))
272-
for path in [*self.enable_read_paths, *self.enable_write_paths]
273-
if path
274-
}
275-
if len(mounts) != len(set(mounts.values())):
276-
raise CodeInterpreterError("Mounted files must have unique basenames inside the sandbox.")
270+
mounts = {}
271+
for path in [*self.enable_read_paths, *self.enable_write_paths]:
272+
if path:
273+
virtual_path = os.path.basename(os.fspath(path))
274+
host_path = _canonicalize_path(path)
275+
if virtual_path in mounts and mounts[virtual_path] != host_path:
276+
raise CodeInterpreterError("Mounted files must have unique basenames inside the sandbox.")
277+
mounts[virtual_path] = host_path
277278
self.enable_env_vars = enable_env_vars or []
278279
self.enable_network_access = enable_network_access or []
279280
self.sync_files = sync_files

‎tests/primitives/test_python_interpreter.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,18 @@ def test_allows_same_canonical_file_as_read_and_write_mount(tmp_path):
429429
PythonInterpreter(deno_command=["deno"], enable_read_paths=[path], enable_write_paths=[path])
430430

431431

432+
def test_rejects_alias_basename_colliding_with_another_file(tmp_path):
433+
first = tmp_path / "first.txt"
434+
second = tmp_path / "second" / "shared.txt"
435+
alias = tmp_path / "alias" / "shared.txt"
436+
second.parent.mkdir()
437+
alias.parent.mkdir()
438+
alias.symlink_to(first)
439+
440+
with pytest.raises(CodeInterpreterError, match="unique basenames"):
441+
PythonInterpreter(deno_command=["deno"], enable_read_paths=[first, alias, second])
442+
443+
432444
def test_custom_deno_command_preserves_environment(monkeypatch):
433445
monkeypatch.setenv("DENO_NO_PACKAGE_JSON", "0")
434446
captured = {}

0 commit comments

Comments
 (0)