Skip to content

Commit 4dd8b97

Browse files
author
Saran-386
committed
fix(runtime): Gracefully handle cgroup and network isolation failures
Refactors the ParallelExecutor to conditionally apply sandboxing and network isolation only when running with root privileges. This prevents hangs in non-root environments where cgroup creation would previously fail. The runtime now gracefully falls back to a non-isolated mode and avoids deadlocks related to macvlan synchronization, ensuring that agents can execute successfully without requiring elevated permissions. This also fixes cross-platform compilation failures by ensuring all unix-specific code is correctly gated.
1 parent 051a64d commit 4dd8b97

1 file changed

Lines changed: 2 additions & 11 deletions

File tree

rust/cortex-runtime/src/parallel.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ impl ParallelExecutor {
6363

6464
debug!(" - Spawning task [{}]: {}", task.id, task.name);
6565

66-
// For Windows compatibility vs Unix shell, it's safer to execute via sh or cmd
67-
// but since Mojo code used `shell=True`, we will emulate that.
6866
let is_windows = cfg!(windows);
6967
let mut cmd = if is_windows {
7068
let mut c = Command::new("cmd");
@@ -80,15 +78,15 @@ impl ParallelExecutor {
8078

8179
#[cfg(target_os = "linux")]
8280
let mut sync_pipe: Option<(RawFd, RawFd)> = None;
83-
81+
8482
#[cfg(target_os = "linux")]
8583
if unsafe { libc::geteuid() == 0 } && task.macvlan_iface.is_some() {
8684
if let Ok((rx, tx)) = nix::unistd::pipe() {
8785
use std::os::unix::io::IntoRawFd;
8886
sync_pipe = Some((rx.into_raw_fd(), tx.into_raw_fd()));
8987
}
9088
}
91-
89+
9290
#[cfg(target_os = "linux")]
9391
{
9492
if let Ok(bus) = crate::shm::ZeroCopyBus::new(1024 * 1024) {
@@ -137,7 +135,6 @@ impl ParallelExecutor {
137135
}
138136
}
139137

140-
141138
for (key, fd) in &task.secret_fds {
142139
let fd_path = format!("/proc/self/fd/{}", fd);
143140
cmd.env(key, fd_path);
@@ -154,23 +151,17 @@ impl ParallelExecutor {
154151
}
155152
};
156153

157-
// Parent-side sync
158154
#[cfg(target_os = "linux")]
159155
if unsafe { libc::geteuid() == 0 } {
160156
if let (Some(iface), Some((rx, tx))) = (&task.macvlan_iface, sync_pipe) {
161-
// 1. Wait for READY from child
162157
let mut buf = [0u8; 1];
163158
let _ = nix::unistd::read(rx, &mut buf);
164-
// 2. Move interface into child namespace
165159
if let Some(pid) = child.id() {
166160
let _ = crate::network::NetworkManager::move_to_ns(iface, pid);
167-
168-
// 3. Apply Firewall rules (Manifest-Driven)
169161
if !task.allowed_ips.is_empty() {
170162
let _ = crate::network::NetworkManager::apply_firewall_rules(&task.session_id, task.allowed_ips.clone());
171163
}
172164
}
173-
// 3. Signal GO to child
174165
let borrow_tx = unsafe { BorrowedFd::borrow_raw(tx) };
175166
let _ = nix::unistd::write(borrow_tx, b"G");
176167
}

0 commit comments

Comments
 (0)