Run a one-shot command inside the sandbox via `openshell sandbox exec`. Used by tests that need to pre-populate sandbox-side state (create files, symlinks, directories) without going through the upload flow. Stdout and stderr are captured and returned together; PTY allocation is disabled so the call is suitable for non-interactive setups. # Arguments `argv` — Command and arguments to execute (p
(&self, argv: &[&str])
| 371 | /// |
| 372 | /// Returns an error if the CLI exits non-zero. |
| 373 | pub async fn exec(&self, argv: &[&str]) -> Result<String, String> { |
| 374 | let mut cmd = openshell_cmd(); |
| 375 | cmd.arg("sandbox") |
| 376 | .arg("exec") |
| 377 | .arg("--name") |
| 378 | .arg(&self.name) |
| 379 | .arg("--no-tty") |
| 380 | .arg("--"); |
| 381 | for arg in argv { |
| 382 | cmd.arg(arg); |
| 383 | } |
| 384 | cmd.stdout(Stdio::piped()).stderr(Stdio::piped()); |
| 385 | |
| 386 | let output = cmd |
| 387 | .output() |
| 388 | .await |
| 389 | .map_err(|e| format!("failed to spawn openshell exec: {e}"))?; |
| 390 | |
| 391 | let stdout = String::from_utf8_lossy(&output.stdout).to_string(); |
| 392 | let stderr = String::from_utf8_lossy(&output.stderr).to_string(); |
| 393 | let combined = format!("{stdout}{stderr}"); |
| 394 | |
| 395 | if !output.status.success() { |
| 396 | return Err(format!( |
| 397 | "sandbox exec failed (exit {:?}):\n{combined}", |
| 398 | output.status.code() |
| 399 | )); |
| 400 | } |
| 401 | |
| 402 | Ok(combined) |
| 403 | } |
| 404 | |
| 405 | /// Download files from the sandbox via `openshell sandbox download`. |
| 406 | /// |