nanocoder icon indicating copy to clipboard operation
nanocoder copied to clipboard

[Bug] Sandbox jail temp dir is deleted while child process group is still alive on cancel/timeout

Open rishu685 opened this issue 1 month ago • 2 comments

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

  1. Enable sandbox mode — set "sandbox": true in agents.config.json
  2. Start a command that writes to temp files heavily, e.g. execute_bash("npm install") or execute_bash("cargo build")
  3. Cancel the execution within 1–2 seconds of launch (before the internal SIGKILL fires)
  4. Observe ENOENT: no such file or directory errors 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.

rishu685 avatar Oct 09 '26 06:10 rishu685

Would love to fix this if once confirmed

rishu685 avatar Oct 09 '26 06:10 rishu685

Sure @rishu685 👍

akramcodez avatar Oct 09 '26 09:10 akramcodez