[BUG] TS sandbox: streamProcess never sends SIGKILL, so a command that ignores SIGTERM outlives its timeout
Human Overview
To be filled in by a human (AI-drafted issue, see team/AI_USAGE_POLICY.md).
Checks
- [x] I have updated to the lastest minor and patch version of Strands
- [x] I have checked the documentation and this is not expected behavior
- [x] I have searched ./issues and there are no duplicates of my issue
SDK Language
TypeScript
Strands Version
main @ 794d37c6e (@strands-agents/sdk 0.0.1-development); also present at 7296caba7
Language Runtime Version
Node.js 24.15.0
Operating System
macOS 26.7.3
Installation Method
git clone
Steps to Reproduce
On timeout or abort, streamProcess sends SIGTERM and schedules a SIGKILL for one second later. The generator then exits straight away and its finally clears that timer, so the SIGKILL never fires. A command that ignores SIGTERM keeps running after execute reported the timeout.
import { execSync } from 'node:child_process'
import { readFileSync } from 'node:fs'
import { Agent } from '@strands-agents/sdk'
const pidFile = '/tmp/sigkill-repro.pid'
const agent = new Agent({ printer: false })
try {
await agent.sandbox.execute(`echo $$ > ${pidFile}; trap '' TERM; sleep 30`, { timeout: 0.3 })
} catch (e) {
console.log('execute rejected with', (e as Error).name)
}
await new Promise((r) => setTimeout(r, 2500))
const pid = readFileSync(pidFile, 'utf8').trim()
try {
console.log('2.5 s later:\n' + execSync(`ps -o pid,stat,command -p ${pid}`).toString())
execSync(`kill -9 ${pid}`)
} catch {
console.log('2.5 s later the shell is gone')
}
Expected Behavior
The shell is killed with SIGKILL about one second after the SIGTERM, so 2.5 s later the shell is gone.
Actual Behavior
execute rejected with SandboxTimeoutError
2.5 s later:
PID STAT COMMAND
81109 S sh -c cd '...' && echo $$ > /tmp/sigkill-repro.pid; trap '' TERM; sleep 30
Additional Context
Related:
- #5044: the kill reaches only the
shwrapper, not its children. - #5184, the open fix for #5044: it moves the signals to the process group but keeps the
clearTimeout(killTimer)infinally, so it does not change this. A group that ignoresSIGTERMwould survive in the same way.
The Python SDK's stream_process sends SIGKILL to the process group on timeout (strands-py/src/strands/sandbox/stream_process.py:33-39, :119-124), so it is not affected.