Your own team of AI bots in one self-hosted binary: spaces, every account you have, handoffs, approvals and routines. Open-source, self-hosted alternative to Grok Bot, Claude Duet and OpenAI dots. Rust + React.
Rust ai-agentsai-assistantai-botautomationbotbots-teamchatbotclaude-duetgrokgrok-botgrok-bot-alternativeharnessllmmulti-agentopenai-dotsopenbotpersonal-agentrustself-hostedselfhosted-ai
Refuse VM-mode shell commands with no known bot or team instead of running on the host
Lin (kwant bot)7d0307575957
diff --git a/src/server/routes.rs b/src/server/routes.rsindex fd0f550c..9861520b 100644--- a/src/server/routes.rs+++ b/src/server/routes.rs@@ -2666,17 +2666,25 @@ pub async fn execute_tool(return crate::tools::shell::execute_shell(&workspace, args).await;}if tool_name == "execute_shell" {- if let Some(tid) = team_id {- if let Some((name, workspace)) = resolve_sandbox_target_info(state, tid).await {- tokio::fs::create_dir_all(&workspace).await?;- let sandbox = state.sandbox_manager.ensure_sandbox_running(tid, &name, &workspace).await- .map_err(|e| crate::tools::ToolError::Execution(e.to_string()))?;- let out = state.sandbox_manager.exec_in_sandbox(&sandbox.container_name,- args["command"].as_str().unwrap_or(""), 30).await- .map_err(|e| crate::tools::ToolError::Execution(e.to_string()))?;- return Ok(json!({"command":out.command,"stdout":out.stdout,"stderr":out.stderr,"exit_code":out.exit_code,"success":out.success}));- }- }+ // VM mode: commands only ever run inside the bot's or team's sandbox. With no known+ // target there is no sandbox to use, so refuse rather than fall back to this computer.+ let target = match team_id {+ Some(tid) => resolve_sandbox_target_info(state, tid).await.map(|t| (tid, t)),+ None => None,+ };+ let Some((tid, (name, workspace))) = target else {+ return Err(crate::tools::ToolError::Execution(format!(+ "No bot or team named '{}' was found, so the command was not run. In VM mode commands only run inside a bot's or team's sandbox.",+ team_id.unwrap_or("")+ )));+ };+ tokio::fs::create_dir_all(&workspace).await?;+ let sandbox = state.sandbox_manager.ensure_sandbox_running(tid, &name, &workspace).await+ .map_err(|e| crate::tools::ToolError::Execution(e.to_string()))?;+ let out = state.sandbox_manager.exec_in_sandbox(&sandbox.container_name,+ args["command"].as_str().unwrap_or(""), 30).await+ .map_err(|e| crate::tools::ToolError::Execution(e.to_string()))?;+ return Ok(json!({"command":out.command,"stdout":out.stdout,"stderr":out.stderr,"exit_code":out.exit_code,"success":out.success}));}let runner = match controller {diff --git a/tests/sandbox_tools_test.rs b/tests/sandbox_tools_test.rsindex 552a3945..f624f499 100644--- a/tests/sandbox_tools_test.rs+++ b/tests/sandbox_tools_test.rs@@ -177,18 +177,46 @@ async fn test_execute_tool_shell_fallback() {let router = LayaRouter::new(config.laya_url.clone());let state = AppState::new(config, db, tools, broker, router);+ state.db.set_setting("computer_mode", "vm").await.unwrap();- let res = kwnt::server::routes::execute_tool(+ // vm mode with an unknown team: refused with a clear error, never run on this computer+ let err = kwnt::server::routes::execute_tool(&state,Some("team-test"),"execute_shell",&json!({ "command": "echo 'sandboxed-fallback'" }),).await- .unwrap();+ .unwrap_err();+ let msg = err.to_string();+ assert!(msg.contains("team-test") && msg.contains("not run"), "{msg}");+}++#[tokio::test]+async fn test_vm_shell_unknown_target_never_runs_on_host() {+ let tmp = tempdir().unwrap();+ let db = Database::init(tmp.path()).await.unwrap();+ let config = Config { data_dir: tmp.path().to_path_buf(), browser_cdp_url: Some("http://127.0.0.1:9".into()), ..Config::default() };+ let workspace = tmp.path().join("workspace");+ std::fs::create_dir_all(&workspace).unwrap();+ let tools = ToolRunner::new(workspace.clone());+ let broker = PermissionBroker::new();+ let router = LayaRouter::new(config.laya_url.clone());- assert_eq!(res["exit_code"], 0);- assert!(res["stdout"].as_str().unwrap().contains("sandboxed-fallback"));+ let state = AppState::new(config, db, tools, broker, router);+ state.db.set_setting("computer_mode", "vm").await.unwrap();+ let mut rx = state.event_sender.subscribe();++ let marker = tmp.path().join("ran-on-host.txt");+ let cmd = format!("touch '{}'", marker.display());+ for team in [Some("no-such-team"), Some(""), None] {+ let res = kwnt::server::routes::execute_tool(&state, team, "execute_shell", &json!({ "command": cmd })).await;+ assert!(res.is_err(), "{team:?}: must be refused, got {res:?}");+ assert!(!marker.exists(), "{team:?}: command ran on the host");+ }+ assert!(std::fs::read_dir(&workspace).unwrap().next().is_none(), "host workspace must stay untouched");+ // refused outright: no approval prompt, since vm mode never offers host execution+ assert!(rx.try_recv().is_err());}#[tokio::test]