What You’ll Learn
- Starting a background process with
sbx.commands.run(cmd, background=True) - Inspecting the returned
CommandHandleand itspid - Listing all running processes with
sbx.commands.list() - Killing a process by PID with
sbx.commands.kill(pid) - Verifying the process was removed by listing again
- Proper cleanup with
try/finallyandsbx.kill()
Prerequisites
This example is available in Python. TypeScript version coming soon.
Code Walkthrough
Start a command in the background by passingbackground=True. The call returns immediately with a CommandHandle containing the process PID:
pid and cmd: