Streaming command output
To stream command output as it is being executed, pass the onStdout
, onStderr
callbacks to the commands.run()
method in JavaScript
or the on_stdout
, on_stderr
callbacks to the commands.run()
method in Python.
import { Sandbox } from '@e2b/code-interpreter'
const sandbox = await Sandbox.create()
const result = await sandbox.commands.run('echo hello; sleep 1; echo world', {
onStdout: (data) => {
console.log(data)
},
onStderr: (data) => {
console.log(data)
},
})
console.log(result)