Skip to content

sandbox: bound subprocess output capture in run_process (apply #929 fix to sandbox exec path) #1016

Description

@AmitoVrito

Found during review of #940 (PC Twin sandbox).

sandbox/backends/base.py:run_process uses process.communicate() with no byte cap, so a sandboxed command emitting large output within the command_timeout window (e.g. yes) can exhaust the host process memory before the timeout fires. This is the same class as the already-fixed Agent OS Shell bug #929, which added a hard max_output_bytes cap with streaming — the sandbox exec path did not receive that treatment.

Mitigated by command_timeout and the container mem/pids limits, but output is not bounded by size. Apply a streaming byte cap consistent with the #929 fix.

Activity

  1. added
    bug
    on Sep 3, 2026
  2. added a commit that references this issue on Sep 3, 2026
  3. MohamedIdhries commented on Sep 5, 2026

    @MohamedIdhries
    Contributor

    I inspected the current implementation. run_process has no max_output_bytes parameter, unlike DirectShellExecutor. Should the cap be added as a keyword argument to run_process, sourced from SandboxConfig, or defined as a shared sandbox default?

    I’ll match the existing _drain() and _decode() semantics from src/synapsekit/shell/executor.py once that API decision is confirmed.

  4. AmitoVrito commented on Sep 8, 2026

    @AmitoVrito
    CollaboratorAuthor

    Thanks for digging in. Do both: a max_output_bytes kwarg on run_process (sits next to timeout, defaulted) plus a matching SandboxConfig.max_output_bytes field that the exec path passes through. That mirrors how command_timeout already reaches run_process at docker.py:80. run_process is the low-level primitive and the version probes call it too, so it needs its own defaulted knob; the value people actually tune lives on the config. The one option I would skip is a shared module constant, since you can't override it per sandbox.

    For the value: default 1_000_000 to line up with DirectShellExecutor, and validate > 0 in SandboxConfig.__post_init__ (same check the shell already does).

    The actual fix is swapping process.communicate() for the streaming read in shell/executor.py::_drain — communicate() buffers the whole child output into memory before any limit applies, which is the bug. Read in chunks and kill the child as soon as either stream crosses the cap; keep the [output truncated] suffix from _decode so truncation is visible in the result. If you'd rather not copy _drain/_decode, lifting them into a small shared helper is welcome but not required — a local copy in base.py is fine.

    Ping me on the PR when it's up.

  5. added 4 commits that reference this issue on Sep 12, 2026
    6059199
    69e75e2
    bad0212
    f83a13f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions