#809·flue

Local sandbox: a child that ignores SIGTERM survives an exec() timeout, because the SIGKILL fallback is cancelled when the shell exits

Author: pandyspCreated Oct 2, 2026Updated Oct 2, 2026

Describe the Bug

When exec() in the local (Node) sandbox times out or is aborted, Flue sends SIGTERM to the command's process group and schedules a SIGKILL two seconds later for anything still running (onAbort). That SIGKILL is cancelled if the shell exits first: once the shell's output pipes close, settle() clears the timer.

So a process in the group that ignores SIGTERM and doesn't hold the shell's stdout/stderr keeps running after exec() has already returned its timeout result (exit code 124). In our case such a process kept editing files after the agent had been told the command timed out, so the files on disk no longer matched what the agent and our tooling saw.

Expected Behavior

Nothing from the command's process group is still running once the SIGKILL grace period has passed, whether or not the shell exited earlier. For example, settle() could leave the SIGKILL timer running after an abort, or signal the group with SIGKILL when the shell exits after one.

Steps to Reproduce

  1. npm i @flue/[email protected] (local-env.ts is unchanged on main at 6583259). Seen on macOS with Node 26.5.

  2. Run this as repro.mjs. The command's child ignores SIGTERM and writes a file after 3 seconds; its output goes to /dev/null, so it doesn't keep the shell's pipes open:

    javascript
    import { mkdtemp, readFile } from 'node:fs/promises';
    import { tmpdir } from 'node:os';
    import { join } from 'node:path';
    import { local } from '@flue/runtime/node';
    
    const dir = await mkdtemp(join(tmpdir(), 'flue-sigkill-'));
    const sandbox = await local({ cwd: dir }).createSandbox({ id: 'repro' });
    const result = await sandbox.exec(`sh -c 'trap "" TERM; sleep 3; echo late > late.txt' >/dev/null 2>&1`, { timeoutMs: 500 });
    console.log('exec returned', { exitCode: result.exitCode });
    await new Promise(resolve => setTimeout(resolve, 4000)); // past the 2 s SIGKILL grace period
    console.log('late.txt after 4 s:', await readFile(join(dir, 'late.txt'), 'utf8').catch(() => 'missing'));
  3. Output:

    exec returned { exitCode: 124 }
    late.txt after 4 s: late

    Expected late.txt after 4 s: missing: the child should have been killed two seconds after the timeout.

Related: #630 discusses the opposite case, a leftover child that keeps the pipes open so close never fires.