run-bounded
A command-line tool and Python library for running commands with time, output, and process-tree limits.
Rust 1.82+ · Python 3.9+
5.3 ms per run; a Python subprocess.run call to the same command takes 37.9 ms. Both from the saved 30-run hyperfine file.
Install · Quick start · Why
The demo uses printf with fixed text. It shows command output, not a benchmark.
Install
pipx install run-bounded
uv tool install run-bounded
pip install run-bounded
Python 3.9+. Wheels for macOS, Linux and Windows install the run-bounded binary and the importable
Python package bounded_run; no Rust toolchain is needed.
From source (Rust 1.82 or newer):
git clone https://github.com/elfenomenokim/run-bounded
cd run-bounded
cargo install --locked --path .
Quick start
run-bounded --timeout 5 --idle 2 --max-output 1K -- printf 'bounded output\n'
printf resolves through PATH. Absolute executable paths also work. Relative paths containing / or \ are rejected.
The child keeps stdout and stderr. The command writes one JSON result line to stderr:
bounded output
{"class":"ok","duration_ms":6,"exit_code":0,"stdout_truncated":false,"stderr_truncated":false}
--timeout sets wall seconds. --idle sets seconds without output. --max-output sets the default per-stream byte cap (--max-stdout and --max-stderr override each stream); K, M, and G use powers of 1024. Zero disables a time limit. run-bounded --help lists every option. Child stdin is closed by default unless --stdin inherit or --input is given. The child receives a small environment with PATH, locale, home, temporary-directory, and Windows system variables.
Run in a specific directory with separate stream caps, passed input, and --kill-on-cap:
run-bounded --cwd /tmp --input $'line 1\nline 2\n' --max-stdout 7 --max-stderr 256 --kill-on-cap -- cat
line 1
{"class":"output_limit","duration_ms":5,"exit_code":0,"stdout_truncated":true,"stderr_truncated":false}
Why
run-bounded drains stdout and stderr independently and limits each stream. On Unix, it starts a new process group and sends TERM followed by KILL when a limit expires. Windows assigns the child to a Job Object and terminates the job on timeout. The Rust CLI is one binary; the Python edition is importable without a native extension. feno-cli keeps its existing run_process_group API.
| Tool | Wall timeout | Output cap | Grandchild after timeout |
|---|---|---|---|
| run-bounded | yes | per stream | terminated on macOS, Linux, and Windows checks |
coreutils gtimeout |
yes | no | remained alive in the macOS check |
Python subprocess.run(timeout=...) |
yes | no | remained alive in the macOS check |
How it works
The source is flow.mmd; the Korean README has Korean labels.
Measurements
These are hyperfine 2.0.0 wall-time means and standard deviations for /usr/bin/true. The host was macOS 27.0 on arm64. Each command ran 3 warmups and 30 measured runs. Python command rows include starting the Python interpreter for each run.
| Command | Mean ± standard deviation |
|---|---|
| run-bounded CLI | 5.3 ± 0.8 ms |
gtimeout |
6.2 ± 0.7 ms |
Python subprocess.run |
37.9 ± 3.5 ms |
| Python library command | 61.7 ± 15.4 ms |
Re-run from the CCH repository root. The saved measurements are in macos-27-arm64-20261117.json.
cargo build --locked --release --manifest-path docs/products/feno-cli/bounded-run/Cargo.toml
hyperfine --shell=none --warmup 3 --runs 30 \
--export-json docs/products/feno-cli/bounded-run/docs/bench/macos-27-arm64-20261117.json \
--command-name 'run-bounded' './docs/products/feno-cli/bounded-run/target/release/run-bounded --timeout 5 --idle 2 -- /usr/bin/true' \
--command-name 'gtimeout' '/opt/homebrew/bin/gtimeout 5 /usr/bin/true' \
--command-name 'Python subprocess.run' '/usr/bin/python3 -c "import subprocess; subprocess.run([\"/usr/bin/true\"], check=True)"' \
--command-name 'Python library' '/usr/bin/python3 -c "import sys; sys.path.insert(0, \"docs/products/feno-cli/bounded-run/python\"); from bounded_run import run; run([\"/usr/bin/true\"])'
Inside an already-started Python interpreter, bounded_run.run() had a 3.5 ms median over 30 calls; the saved samples include the command and host details. The grandchild comparison used a child that ignored TERM and slept for 30 seconds. run-bounded removed it; gtimeout and subprocess.run(timeout=...) left it alive.
Reference
run-bounded [OPTIONS] -- COMMAND [ARGS...]
COMMAND can be an absolute executable path or a bare name found on PATH. --cwd sets the working directory. --stdin defaults to null (closed); pass inherit to keep parent stdin, or --input to feed UTF-8 text and close stdin. --max-stdout and --max-stderr override --max-output per stream. --kill-on-cap terminates the process group or Job Object when either stream exceeds its cap and classifies the run as output_limit (exit code 1).
--idle-stream stdoutresets the idle clock on stdout activity only. The default,either, counts both streams.--env-exactpasses the runner's entire environment to the child. Set the environment when launching the runner to control which variables it receives. The default uses the small allowlist above.--capture-overflow-byteforwards the first byte over each cap for diagnostics while preserving the cap's kill threshold.--term-grace SECsets the Unix TERM grace when a limit fires. The default is 0.2 seconds. Zero sends KILL directly. Windows uses its Job Object.--max-total-output BYTESsets an additional shared cap for stdout and stderr. Bytes from both streams count, including bytes discarded by a per-stream cap. The readers use the shared budget in the order they read chunks. Any omitted bytes set the corresponding truncation flag.--kill-on-capalso applies to the shared cap. The optional per-stream overflow byte must fit inside the shared cap.--no-reaprequests immediate process-tree cleanup at a time limit or a killing output limit, with no TERM grace, then returns without waiting for exit or pending output. If the exit status is still unknown, the result reportsclass: "unknown",abandoned_pid, andlimit(timeout,idle, oroutput_limit). The CLI exit code still reflects the triggering limit.--stdout-file PATHand--stderr-file PATHwrite the child's stream to a file as it arrives instead of forwarding it.--appendopens the file for appending. Delivery is still capped per stream (--max-stdout/--max-stderr), so a sink cannot fill a disk unbounded;--kill-on-capkeeps its meaning.--merge-stderrsends both child streams to the stdout sink in arrival order, one ordered log. The merged stream shares one budget:--max-total-outputwhen given, otherwise--max-stdout. It cannot be combined with--stderr-file,--stderr-keep, or--max-stderr.--stdout-keep tailand--stderr-keep tailkeep the newest capped bytes of a stream in a ring buffer and write them when the stream closes. A tail stream is bounded by construction and never trips--kill-on-capfor its own stream. The defaultheadkeeps the first capped bytes as they arrive. A tail keep cannot feed a--*-filesink.- On SIGINT, SIGTERM or SIGHUP (Windows: CTRL_BREAK or console close), the CLI kills the child tree, reports
class: "cancelled"and exits 130 — distinct from 124 (time limits) and 125 (setup errors).
Python's bounded_run.run() exposes the same controls as idle_stream="stdout", env_exact=True, capture_overflow_byte=True and term_grace=0.2. By default, env overlays the small allowlist. With env_exact=True, the child gets only the env mapping, or an empty environment if omitted. stdin defaults to closed (DEVNULL) and accepts "inherit" or a readable file/fd. input accepts bytes or str. stdout_sink=/stderr_sink= accept a path (opened wb, or ab with sink_append=True), a binary file object, or a callable receiving each chunk in order; returning False from the callable stops the run with classification "stopped", and a callback exception stops the run and is re-raised after cleanup. merge_stderr=True delivers both streams to the stdout sink in arrival order. stdout_keep=/stderr_keep="tail" keep the newest capped bytes of a captured stream. pass_fds=(fd, ...) forwards extra descriptors on POSIX (ValueError on Windows).
bounded_run.start() starts a run and returns a Run handle: pid, poll() -> RunResult | None, wait(timeout=None) -> RunResult (raising TimeoutError past the wait timeout), and cancel(reason="cancelled") (idempotent; TERM then KILL; the context manager cancels on exit). A cancelled run classifies as "cancelled" and records cancel_reason. Handles from start() never install signal handlers. run() keeps the 0.1.8 stop-signal behavior: in the main POSIX thread it temporarily turns SIGINT, SIGTERM and SIGHUP into a stop that kills the child tree, restores the previous handlers and re-raises the signal.
RunResult includes classification, duration, returncode, captured stdout and stderr bytes, truncation flags and the cleanup actions taken, if any. With a sink, stdout/stderr are b"" and stdout_bytes/stderr_bytes report how many bytes the child delivered per stream. Use max_total_output=BYTES for the shared cap and no_reap=True for immediate return. Classifications are ok, failed, timeout, idle, output_limit, signal, stopped, cancelled, and unknown. For unknown, returncode is None and abandoned_pid and limit describe the incomplete run.
Platforms
The CLI was built and exercised on macOS 27.0 arm64, Ubuntu 24.04 arm64 on A1, and Windows build 26340 x64 (reported OS version 10.0.26340.0). The Python library was exercised on macOS and Windows. The Windows Rust build used the laptop's existing Rust 1.100 GNU toolchain. Timeout and idle return 124, output-limit kills return 1, CLI errors return 125, and normal child failures retain the child's exit code. A child terminated by a signal returns 128 plus the signal number, and its JSON exit_code is null. A consumer that stops reading its output cannot delay a timeout result: once a limit terminates the child, both editions report the timeout without waiting for the blocked output write or for a descendant that left the process group. When the runner itself receives SIGINT, SIGTERM or SIGHUP, it stops the child tree first, writes a cancelled verdict and exits 130; on Windows, CTRL_BREAK and console close do the same. A Windows job also ends its children when the runner closes it.
Contributing
Run cargo build --locked from this directory. Issues and platform reports are welcome.
See CONTRIBUTING.md for the tests and the review process.
License
MIT. See LICENSE.
Metadata
Release files for run-bounded 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| run_bounded-0.2.0-py3-none-win_amd64.whl | Python 3 | none | Windows x86-64 | Details for run_bounded-0.2.0-py3-none-win_amd64.whl |
| run_bounded-0.2.0-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl | Python 3 | none | Linux glibc 2.17+ x86-64 | Details for run_bounded-0.2.0-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
| run_bounded-0.2.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl | Python 3 | none | Linux glibc 2.17+ ARM64 | Details for run_bounded-0.2.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl |
| run_bounded-0.2.0-py3-none-macosx_11_0_arm64.whl | Python 3 | none | macOS 11.0+ ARM64 | Details for run_bounded-0.2.0-py3-none-macosx_11_0_arm64.whl |
| run_bounded-0.2.0-py3-none-macosx_10_12_x86_64.whl | Python 3 | none | macOS 10.12+ x86-64 | Details for run_bounded-0.2.0-py3-none-macosx_10_12_x86_64.whl |
Total release size: 1.3 MB
Release files / run_bounded-0.2.0-py3-none-win_amd64.whl
| Download URL | run_bounded-0.2.0-py3-none-win_amd64.whl |
|---|---|
| Size | 204.6 kB |
| Tags | Python 3 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
fb4320725f63a936fbdcf5367bf85af3460fa91bc1101b50a441a099bf6f3544
|
|
BLAKE2b-256 checksum How to use checksums |
8e1db649638f0eae6526217c02231e8eaafcaab3c9394e04902dd47096a1c170
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.16.0
|
Release files / run_bounded-0.2.0-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
| Download URL | run_bounded-0.2.0-py3-none-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
|---|---|
| Size | 285.9 kB |
| Tags | Linux glibc 2.17+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
9168c3f0ebdaab53ed766fb2165d245f7663782fa6db12a85475afea4427d86d
|
|
BLAKE2b-256 checksum How to use checksums |
73431e55d086b63d174f341d71cfac8b6645c0204ab2069164b0c925d2450ea4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.16.0
|
Release files / run_bounded-0.2.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
| Download URL | run_bounded-0.2.0-py3-none-manylinux2014_aarch64.manylinux_2_17_aarch64.whl |
|---|---|
| Size | 277.9 kB |
| Tags | Linux glibc 2.17+ ARM64 Python 3 |
|
SHA-256 checksum How to use checksums |
f687780ad88e69048551e377d89aeb2bc08b800b037b277054b742224956fc0f
|
|
BLAKE2b-256 checksum How to use checksums |
43ed77d4d8e5faf5cae60b7497805823274a41b4110aecdcee480d67c5122b34
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.16.0
|
Release files / run_bounded-0.2.0-py3-none-macosx_11_0_arm64.whl
| Download URL | run_bounded-0.2.0-py3-none-macosx_11_0_arm64.whl |
|---|---|
| Size | 267.3 kB |
| Tags | Python 3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
e28bf972409f3c734e4d45c71237e00ea65d96c1869732577946b8bf3bbacb5e
|
|
BLAKE2b-256 checksum How to use checksums |
27bc58858612675fa3efe24e68cec4ff0657bb77ebbfbf3e410f203b76846ad3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.16.0
|
Release files / run_bounded-0.2.0-py3-none-macosx_10_12_x86_64.whl
| Download URL | run_bounded-0.2.0-py3-none-macosx_10_12_x86_64.whl |
|---|---|
| Size | 271.4 kB |
| Tags | Python 3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
62f7097811d7e7d2dca464f132d67b1f336f84758c356974ac4f95ed5e6814cb
|
|
BLAKE2b-256 checksum How to use checksums |
aae7af179e1bf4ae3bc011598bcb7dcb4ee43b78124d0432a8eb230134ac6e41
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
maturin/1.16.0
|
Security for run-bounded 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.