orxtra v0.13.0 /tool.src.orxtra.tool._subprocess
On this page

run_subprocess forks a pinned executable with timeout enforcement (SIGTERM then SIGKILL) and preview-truncated stdout/stderr capture; validate_exec_arg rejects shell metacharacters and path escapes. Shared by exec and monty command.

#tool.src.orxtra.tool._subprocess

#tool.src.orxtra.tool._subprocess

Reusable subprocess execution machinery.

Relocated from _exec_tool.py to serve both the exec tool and the monty command capability. The core logic is identical: fork a pinned executable with validated arguments, enforce a timeout via SIGTERM/SIGKILL, and return structured output.

#validate_exec_arg

python
def validate_exec_arg(arg: str, read_root: Path) -> None

Validate a single exec tool argument for safety.

Checks:

  1. Reject shell metacharacters (defense-in-depth).
  2. If the arg looks like a path (contains / or \), verify it

resolves within read_root.

Raises:

  • ToolError: If the argument fails validation.

#run_subprocess

python
async def run_subprocess(*, executable: str, args: list[str], cwd: Path, timeout: int, arg_validation: bool, preview_threshold: int, preview_lines: int) -> ToolOutput[ExecResult]

Run a subprocess with timeout enforcement and output capture.

Args:

  • executable: The binary to run.
  • args: Command-line arguments.
  • cwd: Working directory for the subprocess.
  • timeout: Maximum execution time in seconds.
  • arg_validation: When True, validate each argument for safety.
  • preview_threshold: Byte threshold for stdout/stderr preview.
  • preview_lines: Number of head/tail lines in previews.

Returns:

  • A ToolOutput containing the ExecResult.
Search