Skip to content

sandbox="local" + sandbox-tools is not well supported across multiple samples #4496

Description

@craig-meridian

Using the sandbox-tools server with sandbox="local" (e.g. agents that use exec_remote, like claude_code() from inspect_swe) has two intertwined lifecycle problems when running more than one sample. Unlike Docker/K8s — where the server is cleaned up implicitly when the container stops — nothing manages the server's lifecycle in local mode.

1. Stale CWD. The server is started during injection with CWD = the sandbox's TemporaryDirectory. After sample_cleanup deletes that temp dir, the server keeps running with a dangling CWD, and subsequent samples reuse the dead server (the eager start-server is a no-op while the socket is responsive). Child processes then inherit the stale CWD:

sh: 0: getcwd() failed: No such file or directory

2. Orphaned server processes. The server runs indefinitely as an orphaned process with no cleanup. Today there's a single global server; moving to a per-sandbox server (as proposed below) would multiply this into many orphaned processes.

Context / prior work

#3695 proposed making SERVER_DIR configurable via INSPECT_SANDBOX_TOOLS_DIR and having LocalSandboxEnvironment set it per-instance, so each sandbox gets its own server scoped to its temp dir. That fixes problem (1) cleanly, but magnifies problem (2). The PR was closed rather than merged.

Suggested direction

If we revisit this, one option is to pair the per-sandbox scoping from #3695 with explicit tracking of spawned servers and cleaning them up (e.g. during sample_cleanup / task teardown). See the closed PR for the working fix to the CWD half and the approaches considered there.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions