Background commands
Set background to start a command without waiting for it. The returned handle contains the process ID and can wait for, disconnect from, or stop the command.
mjs
import { Sandbox } from "@abox-dev/sdk";
const sandbox = await Sandbox.create();
try {
const command = await sandbox.commands.run(
"sleep 1; printf 'job finished' > /tmp/job.txt",
{ background: true, timeoutMs: 0 },
);
const pid = command.pid;
await command.disconnect();
const reconnected = await sandbox.commands.connect(pid);
await reconnected.wait();
console.log(await sandbox.files.read("/tmp/job.txt"));
} finally {
await sandbox.kill();
}Save both the sandbox ID and process ID when another application process will collect the result. Connect to the sandbox first, then call sandbox.commands.connect(pid).
Live output callbacks belong to the connection that started the command. Write important output to a file when it must remain available after disconnecting. Use timeoutMs: 0 in JavaScript or timeout=0 in Python for a command that must not have its own execution timeout, and keep the sandbox timeout long enough for the job.