Skip to content

Commit d83cb8c

Browse files
committed
fix: enable apt/sudo in Basilica containers
- Remove install command filtering that stripped apt-get/sudo commands - Instead, auto-prefix root commands with sudo when needed - Grant agent user passwordless sudo in Dockerfile - Basilica containers now support apt/sudo at runtime
1 parent d974c07 commit d83cb8c

File tree

2 files changed

+20
-22
lines changed

2 files changed

+20
-22
lines changed

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ ENV PATH="/root/.cargo/bin:${PATH}"
4545
RUN mkdir -p /etc/pip && printf '[global]\nbreak-system-packages = true\n' > /etc/pip/pip.conf
4646

4747
# Create non-root 'agent' user to run the executor and all agent code.
48-
# Basilica containers have no_new_privs, so sudo is unavailable at runtime.
49-
# All system deps must be pre-installed above (as root during build).
48+
# Basilica containers now support sudo/apt at runtime.
5049
RUN useradd -m -s /bin/bash agent \
50+
&& echo "agent ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers \
5151
&& cp -r /root/.cargo /home/agent/.cargo \
5252
&& chown -R agent:agent /home/agent/.cargo \
5353
&& mkdir -p /home/agent/.local/bin \

src/executor.rs

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -74,33 +74,31 @@ async fn run_shell(
7474
run_cmd(&["sh", "-c", shell_cmd], cwd, timeout, env).await
7575
}
7676

77-
/// Filter out system-level package commands that require root (apt-get, dpkg, etc.).
78-
/// In Basilica containers, the executor runs as non-root with no_new_privs,
79-
/// so apt/sudo commands cannot succeed at runtime.
80-
/// All system deps must be pre-installed in the Docker image at build time.
77+
/// Prepare install commands for execution.
78+
/// Basilica containers now support apt/sudo at runtime.
79+
/// Commands requiring root (apt-get, dpkg, etc.) are prefixed with sudo
80+
/// if not already using sudo.
8181
fn filter_install_command(cmd: &str) -> String {
82-
let system_prefixes = [
83-
"apt-get",
84-
"apt ",
85-
"dpkg",
86-
"yum ",
87-
"dnf ",
88-
"pacman ",
89-
"apk ",
90-
"snap ",
91-
"flatpak ",
92-
"sudo apt",
93-
"sudo dpkg",
82+
let root_prefixes = [
83+
"apt-get", "apt ", "dpkg", "yum ", "dnf ", "pacman ", "apk ",
9484
];
9585

9686
let parts: Vec<&str> = cmd.split("&&").collect();
97-
let filtered: Vec<&str> = parts
87+
let processed: Vec<String> = parts
9888
.iter()
99-
.map(|p| p.trim())
100-
.filter(|p| !system_prefixes.iter().any(|prefix| p.starts_with(prefix)))
89+
.map(|p| {
90+
let trimmed = p.trim();
91+
if trimmed.starts_with("sudo ") {
92+
trimmed.to_string()
93+
} else if root_prefixes.iter().any(|prefix| trimmed.starts_with(prefix)) {
94+
format!("sudo {}", trimmed)
95+
} else {
96+
trimmed.to_string()
97+
}
98+
})
10199
.collect();
102100

103-
filtered.join(" && ")
101+
processed.join(" && ")
104102
}
105103

106104
pub struct Executor {

0 commit comments

Comments
 (0)