Skip to content

execute_code sandbox fails with OSError: AF_UNIX path too long when TMPDIR is long on Linux #61043

Description

@MSandro

Summary

On Linux, execute_code always fails with OSError: AF_UNIX path too long when the host process's TMPDIR is longer than roughly the length of /tmp (i.e. whenever TMPDIR isn't literally /tmp). Every call returns tool_calls_made: 0 — the sandbox never starts.

Root cause

tools/code_execution_tool.py (around line 1200–1263, v0.18.2) builds the sandbox RPC socket path as:

_sock_tmpdir = "/tmp" if sys.platform == "darwin" else tempfile.gettempdir()
...
sock_path = os.path.join(_sock_tmpdir, f"hermes_rpc_{uuid.uuid4().hex}.sock")
...
server_sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
server_sock.bind(sock_path)  # line 1263 — raises here

The comment above this code says: "On Linux, tempfile.gettempdir() already returns /tmp" — but that's only true when TMPDIR/TMP/TEMP are unset. Any host that sets a longer TMPDIR (e.g. for per-task/per-workspace sandbox isolation) pushes tempfile.gettempdir() well past a short path, and the appended hermes_rpc_<32-hex-chars>.sock filename (~51 chars) then blows past Linux's sun_path limit (108 bytes, ~107 usable).

Concretely, with a 117-char TMPDIR the resulting socket path was 166 chars — bind() fails every time with OSError: AF_UNIX path too long.

The macOS branch already works around a version of this same problem (avoiding the long /var/folders/... TMPDIR), but the Linux branch assumes the default tempdir is always short, which isn't true once TMPDIR is overridden.

Suggested fix

Drop the darwin-only special case and always anchor the sandbox socket at a short, fixed directory (e.g. always use /tmp regardless of sys.platform, or fall back to /tmp whenever len(sock_path) > 100), instead of trusting tempfile.gettempdir() on Linux.

Environment

  • hermes-agent 0.18.2
  • Linux
  • Triggered whenever the host process sets a TMPDIR longer than a few chars before launching hermes (e.g. per-task temp dir isolation)

Impact

execute_code is completely non-functional under these conditions — every invocation fails immediately with 0 tool calls made.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium — degraded but workaround existscomp/toolsTool registry, model_tools, toolsetstool/code-execexecute_code sandboxtype/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions