fix(tools): require python3 for Box native file scripts (#2658)

* fix(tools): require python3 for Box native file scripts

Unversioned `python` is still Python 2 on some host-rootfs nsjail
mounts. Falling back to it made read/write/edit scripts fail with
SyntaxError on f-strings (#2603).

Resolve only `python3`, and return a clear JSON error when it is
missing instead of invoking Python 2.

Fixes #2603

* style(tools): format Box interpreter error command

Co-authored-by: multica-agent <[email protected]>

---------

Co-authored-by: Li-john1021 <[email protected]>
Co-authored-by: Chin Rock <[email protected]>
Co-authored-by: multica-agent <[email protected]>
This commit is contained in:
Li-john1021
2026-10-19 14:46:47 +08:00
committed by GitHub
co-authored by multica-agent Li-john1021 Chin Rock
parent 5c3675f4cc
commit bce94bd0d9
2 changed files with 16 additions and 6 deletions
@@ -747,10 +747,18 @@ class NativeToolLoader(loader.ToolLoader):
return f'{str(base).rstrip("/")}/{relative}'
async def _run_workspace_file_script(self, script: str, query: pipeline_query.Query) -> dict:
# Sandbox images built from a host rootfs may only ship `python3`, and a
# read-only /usr prevents creating a `python` shim inside the jail, so
# resolve the interpreter instead of assuming its name.
command = f'PYTHON_BIN=$(command -v python3 || command -v python); "$PYTHON_BIN" - <<\'PY\'\n{script}\nPY'
# Box file tools need Python 3 (f-strings, etc.). Prefer `python3` and
# never fall back to unversioned `python`, which may still be Python 2
# on host-rootfs nsjail mounts (LangBot #2603). Missing python3 yields a
# clear JSON error instead of a SyntaxError tool result.
command = (
'PYTHON_BIN=$(command -v python3 || true); '
'if [ -z "$PYTHON_BIN" ]; then '
'printf \'%s\\n\' \'{"ok": false, "error": "Python 3 interpreter not found in Box (python3 required for native file tools)"}\'; '
'exit 0; '
'fi; '
f'"$PYTHON_BIN" - <<\'PY\'\n{script}\nPY'
)
result = await self.ap.box_service.execute_tool(
{
'command': command,