> ## 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 Commands Inside Your Sandbox

> Execute short, non-streaming commands within a Fermion Sandbox and return stdout and stderr once complete using the Python SDK.

The `run_command()` method executes a short-lived command inside your active sandbox container and waits for it to finish before returning the output.

It’s ideal for quick, synchronous tasks such as listing files, checking Python or Node.js versions, or running lightweight scripts that complete within a few seconds.

This method captures both `stdout` and `stderr` once the command completes. Because it’s optimized for speed and simplicity, `run_command()` has a **strict 5-second execution limit** and does **not support streaming output**.

***

### `async run_command(cmd: str, args: Optional[List[str]] = None) -> CommandResult`

**Description:**\
Executes a short command (\< 5 seconds) and returns its standard output and standard error.\
For longer-running or streaming processes, use `run_streaming_command()` instead.

***

**Parameters:**

| Parameter | Type        | Required | Description                                             |
| --------- | ----------- | -------- | ------------------------------------------------------- |
| `cmd`     | `str`       | Yes      | Command to execute (e.g. `"python3"`, `"ls"`, `"echo"`) |
| `args`    | `List[str]` | No       | List of command arguments                               |

***

**Returns:**

`CommandResult` object with the following attributes:

* `stdout: str` - Standard output
* `stderr: str` - Standard error
* `exit_code: int` - Exit code (defaults to 0)

**Example:**

```python theme={null}
import asyncio
from fermion_sandbox import Sandbox

async def main():
    sandbox = Sandbox(api_key="your-api-key")
    await sandbox.create(should_backup_filesystem=False)

    # Run a simple shell command
    result = await sandbox.run_command(cmd="pwd")

    print("Current directory:", result.stdout)
    print("Exit code:", result.exit_code)

asyncio.run(main())
```

**Limitations:**

* **5 second maximum** : Command will timeout
* No streaming - must wait for completion
* Exit code is always 0 for this method (use `run_streaming_command()` if you need accurate exit codes)
