> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fermion.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Execute Long Running Commands inside your Sandbox

> Execute long-running commands with real-time stdout and stderr streaming inside a Fermion Sandbox.

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:**

| Parameter | Type                   | Required | Description                           |
| --------- | ---------------------- | -------- | ------------------------------------- |
| cmd       | string                 | Yes      | Command to execute                    |
| args      | string\[]              | Yes      | Array of command arguments            |
| stdin     | string                 | No       | Standard input to send to the command |
| onStdout  | (data: string) => void | No       | Callback for stdout data chunks       |
| onStderr  | (data: string) => void | No       | Callback for stderr data chunks       |

**Returns:**

```typescript theme={null}
Promise<{
  stdout: string   // Complete accumulated output
  stderr: string   // Complete accumulated errors
  exitCode: number // Process exit code (0 = success)
}>
```

**Example:**

```typescript theme={null}
// 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`
