[Bug] Sandbox jail temp dir is deleted while child process group is still alive on cancel/timeout
Description
When a sandboxed execute_bash command is cancelled or times out, the per-execution jail
temp directory (jailTmp) is deleted with rmSync immediately after sending SIGTERM —
before the child process group is actually dead. The SIGKILL grace period is 2 seconds,
so any subprocess still running (compilers, npm install, mktemp-heavy toolchains)
will hit ENOENT on every temp file write during that window. This can corrupt partial
build outputs, leave stale lock files on disk, and flood stderr with noise after a cancel
that is supposed to be silent.
Environment
- OS: Linux / macOS (sandbox mode only — does not affect Windows)
- Node version: (run
node --version) - Nanocoder version: (run
nanocoder --version) - Provider: Any
- Model: Any
Steps to Reproduce
- Enable sandbox mode — set
"sandbox": trueinagents.config.json - Start a command that writes to temp files heavily, e.g.
execute_bash("npm install")orexecute_bash("cargo build") - Cancel the execution within 1–2 seconds of launch (before the internal SIGKILL fires)
- Observe
ENOENT: no such file or directoryerrors in stderr for temp paths under the jail directory
Expected Behavior
The jail temp directory (jailTmp) is cleaned up only after the process group is confirmed
dead — i.e., after the close event fires or the SIGKILL timer has confirmed liveness is gone.
Actual Behavior
cancel() calls rmSync(jailTmp, {recursive: true, force: true}) immediately after
sending SIGTERM, while the child process group is still alive and actively writing to
that directory. Any subprocess in the group (compiler, package manager, build tool) that
tries to write a temp file during the 2-second SIGTERM→SIGKILL grace window gets ENOENT.
Affected code: source/services/bash-executor.ts lines 324–330.
Would love to fix this if once confirmed
Sure @rishu685 👍