Run commands
Use sandbox.commands.run to start a command and wait for it to finish. The result contains standard output, standard error, and the exit code.
mjs
import { Sandbox } from "@abox-dev/sdk";
const sandbox = await Sandbox.create();
try {
const result = await sandbox.commands.run("printf 'hello from AgentBox\\n'");
console.log(result.stdout);
} finally {
await sandbox.kill();
}The command runs through a shell. Pass user input through envs instead of inserting it into the command string.
You can also set the working directory, environment variables, user, and timeout. A non-zero exit code raises CommandExitError; it includes the command output and exit code. See the commands reference for all options.