Skip to main content
Terminates a background process by its ID. The process will be sent a termination signal.

Method Signature

await sandbox.killProcess(
  id: string,
  signal?: string,
  sessionId?: string
): Promise<void>

Parameters

id
string
required
The process ID to kill
signal
string
Signal to send to the process (currently not supported by the HTTP client)
sessionId
string
Optional session ID. If not provided, the default session is used.

Returns

void
void
Returns nothing on success. Throws an error if the process is not found or cannot be killed.

Examples

Kill a process by ID

await sandbox.killProcess('dev-server');
console.log('Process killed');

Kill process from Process object

const process = await sandbox.startProcess('python server.py');

// Later...
await process.kill();

Kill with error handling

try {
  await sandbox.killProcess('my-process');
  console.log('Process terminated successfully');
} catch (error) {
  console.error('Failed to kill process:', error.message);
}

Kill all processes matching a pattern

const processes = await sandbox.listProcesses();
const servers = processes.filter(p => 
  p.command.includes('server') && p.status === 'running'
);

for (const process of servers) {
  await sandbox.killProcess(process.id);
}

console.log(`Killed ${servers.length} server processes`);

Build docs developers (and LLMs) love