Optional sandbox for bash, LSP servers and lens/test runners (bwrap, seatbelt)

This commit is contained in:
hermes committed 2026-10-12 16:09:40 +00:00
1 parent d3390a823d
commit 8e7c0bb89a
11 files changed
+586 -17

No files matched your search

+10 -1
View File
@@ -87,6 +87,9 @@ impl Tool for Read {
}
async fn call(&self, a: Value, cx: &ToolCtx) -> ToolResult {
let p = resolve(cx, a["path"].as_str().unwrap_or_default());
if let Err(e) = hx_core::sandbox::guard_read(&p) {
return ToolResult::err(e);
}
let bytes = match tokio::fs::read(&p).await {
Ok(b) => b,
Err(e) => return ToolResult::err(format!("{}: {e}", p.display())),
@@ -161,6 +164,9 @@ impl Tool for Write {
}
async fn call(&self, a: Value, cx: &ToolCtx) -> ToolResult {
let p = resolve(cx, a["path"].as_str().unwrap_or_default());
if let Err(e) = hx_core::sandbox::guard_write(&p) {
return ToolResult::err(e);
}
let c = a["content"].as_str().unwrap_or_default();
if p.exists() && !cx.state.is_fresh(&p) {
return ToolResult::err(format!(
@@ -206,6 +212,9 @@ impl Tool for Edit {
}
async fn call(&self, a: Value, cx: &ToolCtx) -> ToolResult {
let p = resolve(cx, a["path"].as_str().unwrap_or_default());
if let Err(e) = hx_core::sandbox::guard_write(&p) {
return ToolResult::err(e);
}
let (old, new) = (
a["old_string"].as_str().unwrap_or_default(),
a["new_string"].as_str().unwrap_or_default(),
@@ -333,7 +342,7 @@ impl Tool for Bash {
async fn call(&self, a: Value, cx: &ToolCtx) -> ToolResult {
let cmd = a["command"].as_str().unwrap_or_default();
let secs = a["timeout"].as_u64().unwrap_or(120).clamp(1, 3600);
let mut c = tokio::process::Command::new("bash");
let mut c = hx_core::sandbox::command("bash");
c.arg("-c")
.arg(format!("exec 2>&1; {cmd}"))
.current_dir(&cx.cwd)