Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(assistant): terminate timed out command descendants in sandbox (#16262)

Ben Bachem7ebcfacc5a7e
diff --git a/packages/in-app-agent-sandbox-runtime/package.json b/packages/in-app-agent-sandbox-runtime/package.json
index 2a89767d5b..da8d8eaa02 100644
--- a/packages/in-app-agent-sandbox-runtime/package.json
+++ b/packages/in-app-agent-sandbox-runtime/package.json
@@ -9,7 +9,7 @@
"scripts": {
"build": "tsc",
"build:test": "tsc",
- "build:docker-image": "docker build . -t langfuse-in-app-agent-sandbox:latest && touch .local-image-built",
+ "build:docker-image": "tsc && docker build . -t langfuse-in-app-agent-sandbox:latest && touch .local-image-built",
"start": "node ./dist/server.js",
"format": "prettier --write .",
"format:check": "prettier --check ."
diff --git a/packages/in-app-agent-sandbox-runtime/src/server.ts b/packages/in-app-agent-sandbox-runtime/src/server.ts
index 9264faf31c..f8d6dc9944 100644
--- a/packages/in-app-agent-sandbox-runtime/src/server.ts
+++ b/packages/in-app-agent-sandbox-runtime/src/server.ts
@@ -306,7 +306,10 @@ function runCommand(
startedAt: string;
completedAt: string;
}>((resolve, reject) => {
- const child = spawn("sh", ["-lc", command], { cwd: WORKSPACE_ROOT });
+ const child = spawn("sh", ["-lc", command], {
+ cwd: WORKSPACE_ROOT,
+ detached: true,
+ });
let stdout = "";
let stderr = "";
let settled = false;
@@ -350,7 +353,23 @@ function runCommand(
}
settled = true;
- child.kill("SIGKILL");
+ if (child.pid) {
+ try {
+ // Process-group termination is best-effort:
+ // descendants can escape by creating a new session or process group.
+ // A sandbox should have lifetime limits as the final containment boundary.
+ process.kill(-child.pid, "SIGKILL");
+ } catch (error) {
+ logSandboxServer("bash.processGroupKillError", {
+ requestId,
+ pid: child.pid,
+ error: error instanceof Error ? error.message : String(error),
+ });
+ child.kill("SIGKILL");
+ }
+ } else {
+ child.kill("SIGKILL");
+ }
resolve({
stdout,
stderr: `${stderr}Sandbox command timed out after ${timeoutMs}ms`,