# Streaming command output (/docs/commands/streaming)

<!-- agent-signals: reading_time_min: 1 · est_tokens: 343 · updated: 2026-07-30 -->
Related: [Running commands in background](/docs/commands/background.md), [Available servers](/docs/mcp/available-servers.md)

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.

<CodeGroup>
  <CodeBlockTabs defaultValue="JavaScript & TypeScript" groupId="javascript-typescript+python">
    <CodeBlockTabsList>
      <CodeBlockTabsTrigger value="JavaScript & TypeScript">
        JavaScript & TypeScript
      </CodeBlockTabsTrigger>

      <CodeBlockTabsTrigger value="Python">
        Python
      </CodeBlockTabsTrigger>
    </CodeBlockTabsList>

    <CodeBlockTab value="JavaScript & TypeScript">
      ```js  
      import { Sandbox } from 'e2b'

      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)
      ```
    </CodeBlockTab>

    <CodeBlockTab value="Python">
      ```python  
      from e2b import Sandbox

      sandbox = Sandbox.create()

      result = sandbox.commands.run('echo hello; sleep 1; echo world', on_stdout=lambda data: print(data), on_stderr=lambda data: print(data))
      print(result)
      ```
    </CodeBlockTab>
  </CodeBlockTabs>
</CodeGroup>
