Skip to main content

What You’ll Learn

  • Starting a background process with sbx.commands.run(cmd, background=True)
  • Inspecting the returned CommandHandle and its pid
  • 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/finally and sbx.kill()

Prerequisites

This example is available in Python. TypeScript version coming soon.

Code Walkthrough

Start a command in the background by passing background=True. The call returns immediately with a CommandHandle containing the process PID:
List all running processes — each entry has a pid and cmd:
Kill the background process by PID:
List again to confirm the process is gone:

Expected Output