Skip to main content
The runStreamingCommand() method is designed for executing long-running or interactive commands inside a sandbox while receiving real-time output streams.

runStreamingCommand(options)

Description: Executes a long-running command with real-time output streaming. Callbacks are invoked as data arrives. Parameters:
ParameterTypeRequiredDescription
cmdstringYesCommand to execute
argsstring[]YesArray of command arguments
stdinstringNoStandard input to send to the command
onStdout(data: string) => voidNoCallback for stdout data chunks
onStderr(data: string) => voidNoCallback for stderr data chunks
Returns:
Promise<{
  stdout: string   // Complete accumulated output
  stderr: string   // Complete accumulated errors
  exitCode: number // Process exit code (0 = success)
}>
Example:
// Basic streaming
const result = await sandbox.runStreamingCommand({
  cmd: 'npm',
  args: ['install', 'express'],
  onStdout: (data) => console.log(data.trim()),
  onStderr: (data) => console.error(data.trim())
})
console.log('Exit code:', result.exitCode)

// With stdin
const result = await sandbox.runStreamingCommand({
	cmd: 'node',
	args: ['-e', 'process.stdin.on("data", d => console.log(d.toString()))'],
	stdin: 'Hello from stdin\n'
})
Path Handling: When passing file paths or directory paths as command arguments, you can use the ~/ shorthand notation, which the shell automatically expands to the user’s home directory (/home/damner). Examples:
  • ~/file.js expands to /home/damner/file.js
  • ~/project/script.sh expands to /home/damner/project/script.sh
  • ~/code/app.py expands to /home/damner/code/app.py