Skip to content

fix(sandbox): bound subprocess output capture in run_process (fixes #1016) - #1028

Closed
MohamedIdhries wants to merge 1 commit into
SynapseKit:mainfrom
MohamedIdhries:fix/sandbox-bound-output-1016
Closed

MohamedIdhries wants to merge 1 commit into
SynapseKit:mainfrom
MohamedIdhries:fix/sandbox-bound-output-1016

Conversation

@MohamedIdhries

Copy link
Copy Markdown
Contributor

Closes #1016

Summary

  • Added max_output_bytes to SandboxConfig (defaulting to 1,000,000) with > 0 validation in __post_init__.
  • Added max_output_bytes parameter to run_process and updated SandboxBackend.exec / SandboxEnvironment.exec to pass it through.
  • Swapped process.communicate() in sandbox/backends/base.py:run_process for a streaming chunk reader that kills the subprocess as soon as output exceeds max_output_bytes, appending \n[output truncated].
  • Added regression tests in tests/sandbox/test_backends.py.

cc @AmitoVrito

@AmitoVrito

Copy link
Copy Markdown
Collaborator

Merged via #1036 — thanks @MohamedIdhries. This matches the design we landed on in #1016 exactly: concurrent stdout/stderr drain (no pipe deadlock), kills the child on overflow, safe decode with the truncation marker, and the SandboxConfig.max_output_bytes field threaded through SandboxEnvironment into every backend run_process next to command_timeout. Non-breaking, and the regression test drives a real overflowing subprocess. Nicely done.

One small follow-up I filed as #1035: the PCSandbox constructor and attach() do not plumb max_output_bytes yet (it is serialized but not read back), so it is always the 1 MB default through that front door — a parity gap with command_timeout, not a correctness issue. The fix here is fully effective regardless.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants