feat(sandboxd): add command execution limits and bounded output

Merged
HA
1mo ago
+2061-217

What this PR does / why we need it:

Add ExecuteWithLimits for unary command execution with a server-side wall-clock limit independent of the RPC deadline. When the limit expires, sandboxd attempts process-group termination and bounded cleanup. If cleanup succeeds and the RPC remains active, the response includes retained output, the actual exit code, a termination reason, and elapsed duration including cleanup.

Bound stdout and stderr independently. Each stream retains its prefix and continues draining and discarding excess output without terminating the command solely because its logs exceed the capture budget. The response reports truncation for each stream.

Add optional deployment defaults and maximum limits for execution time and each output stream. Both unary execution methods enforce this policy. Legacy Execute returns RESOURCE_EXHAUSTED on execution timeout or output truncation. Older daemons reject the new method with UNIMPLEMENTED, preventing requested limits from being silently ignored.

Regenerate the Go, Python, and TypeScript protocol bindings and document limit resolution, timing, and compatibility. High-level SDK convenience APIs, Start, and PTY execution remain outside this change.

Validation:

  • Targeted Go race tests passed for sandboxd execution, deployment policy, daemon startup, and router forwarding.
  • 29 focused Linux arm64 server tests passed with no failures or skips, including cancellation after leader exit and output-drain cleanup.
  • Targeted go vet, make build-sandboxd, and formatting/whitespace checks passed.

Which issue(s) this PR is related to:

Fixes #1918

Release Note

sandboxd adds ExecuteWithLimits for unary commands with independent execution time limits, bounded stdout/stderr capture, and structured execution outcomes. Optional deployment limits also apply to Execute, which returns RESOURCE_EXHAUSTED on execution timeout or output truncation.

Summary by CodeRabbit

  • New Features
    • Added command execution with optional time limits and separate stdout and stderr capture limits.
    • Results include the exit code, elapsed time, output truncation status, and whether execution ended because of a time limit.
    • Deployments can configure default and maximum execution limits; requests exceeding configured maximums are rejected.
    • Python and TypeScript clients support the new execution option.
  • Behavior Changes
    • Existing command execution now applies deployment limits and returns an error if execution times out or output is truncated.
  • Documentation
    • Added guidance and examples for configuring and using execution limits.