Catch MontyRuntimeError from Monty() constructor

This commit is contained in:
Yiorgis Gozadinos 2026-02-24 12:11:20 +02:00
parent 380fc6c930
commit 1ee9747551
No known key found for this signature in database
2 changed files with 11 additions and 1 deletions

View file

@ -162,7 +162,10 @@ class Sandbox:
inputs=input_names,
external_functions=list(external_fns.keys()),
)
except pydantic_monty.MontySyntaxError as e:
except (
pydantic_monty.MontySyntaxError,
pydantic_monty.MontyRuntimeError,
) as e:
return SandboxResult(stdout="", stderr=str(e), success=False)
stdout_lines: list[str] = []

View file

@ -66,6 +66,13 @@ class TestSandboxErrors:
assert not result.success
assert "NameError" in result.stderr
@pytest.mark.asyncio
async def test_multi_module_import(self, sandbox):
"""Test that unsupported multi-module imports are caught gracefully."""
result = await sandbox.execute("import json, string")
assert not result.success
assert result.stderr != ""
class TestSandboxHaikuRAG:
"""Test haiku.rag functions in sandbox."""