Skip to content

Commit 23b66e7

Browse files
committed
fix(sandbox): raise Linux child process limit
1 parent f257ed0 commit 23b66e7

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

‎crates/openshell-sandbox/src/process.rs‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ use std::process::Stdio;
2222
use tokio::process::{Child, Command};
2323
use tracing::debug;
2424

25+
#[cfg(target_os = "linux")]
26+
const CHILD_NPROC_LIMIT: libc::rlim_t = 8192;
27+
28+
#[cfg(all(unix, not(target_os = "linux")))]
29+
const CHILD_NPROC_LIMIT: libc::rlim_t = 512;
30+
2531
fn inject_provider_env(cmd: &mut Command, provider_env: &HashMap<String, String>) {
2632
for (key, value) in provider_env {
2733
cmd.env(key, value);
@@ -43,13 +49,13 @@ pub fn harden_child_process() -> Result<()> {
4349
));
4450
}
4551

46-
// Limit process creation to prevent fork bombs. 512 processes per UID is
47-
// sufficient for typical agent workloads (shell, compilers, language servers)
48-
// while preventing runaway forking. Set as a hard limit so the sandbox user
49-
// cannot raise it after privilege drop.
52+
// Limit process creation to prevent fork bombs. Linux sandboxes need enough
53+
// headroom for agent runtimes that create many worker threads, while still
54+
// preventing runaway forking. Set as a hard limit so the sandbox user cannot
55+
// raise it after privilege drop.
5056
let nproc_limit = libc::rlimit {
51-
rlim_cur: 512,
52-
rlim_max: 512,
57+
rlim_cur: CHILD_NPROC_LIMIT,
58+
rlim_max: CHILD_NPROC_LIMIT,
5359
};
5460
let rc = unsafe { libc::setrlimit(libc::RLIMIT_NPROC, &raw const nproc_limit) };
5561
if rc != 0 {

0 commit comments

Comments
 (0)