Skip to main content
The Hopx JavaScript SDK provides process management capabilities for monitoring and controlling background code executions.

Background Code Execution

runCodeBackground()

Execute code in the background and return immediately.
const process = await sandbox.runCodeBackground(
  `
import time
for i in range(100):
    print(f"Step {i}")
    time.sleep(1)
`,
  { name: 'long_task' }
);

console.log(`Process ID: ${process.process_id}`);
console.log(`Status: ${process.status}`);
Method Signature:
async runCodeBackground(
  code: string,
  options?: BackgroundExecutionOptions
): Promise<BackgroundExecuteResponse>
Options:
interface BackgroundExecutionOptions {
  language?: string;
  timeout?: number;
  env?: Record<string, string>;
  workingDir?: string;
  name?: string;
}

Listing Processes

listProcesses()

List all background execution processes.
const processes = await sandbox.listProcesses();
for (const proc of processes) {
  console.log(`${proc.name}: ${proc.status} (PID: ${proc.process_id})`);
}
Method Signature:
async listProcesses(): Promise<ProcessInfo[]>

Killing Processes

killProcess()

Terminate a running background process.
await sandbox.killProcess('proc_abc123');
Method Signature:
async killProcess(processId: string): Promise<void>