# Local Shell Command

> Execute shell command on the host machine.

Source: https://docs.sommatic.ai/en/nodes/io.local.shell/

- Slug: `io.local.shell`
- Family: Input and output
- Version: 1.0.0
- Status: Available
- Execution: async

Execute shell command on the host machine.

## Configuration

- `command` (string, required): Command to execute
- `cwd` (string, optional): Current Working Directory
- `timeout` (number, optional): Default: `10000`.

## Output ports

- `out` (default): Command executed successfully
- `error`: Command returned non-zero exit code or failed

## Input contract

- `command` (string, required)
- `cwd` (string, optional)
- `timeout` (number, optional)

## Output contract

- `stdout` (string, optional)
- `stderr` (string, optional)

## In expressions

What a later node can read from this node's output with `$("Local Shell Command").item.json.<path>` (write your node's label instead of `Local Shell Command`). **Editor** marks the paths the workflow editor suggests under Previous Nodes (the output contract); **Worker** marks the paths the worker really returns through `out`, from the output shown in Ports.

- `$("Local Shell Command").item.json.stdout` (string) = `"orders-2026-11-25.csv\norders-2026-11-26.csv"`
- `$("Local Shell Command").item.json.stderr` (string) = `""`


## How it works

Runs a command line through the system shell of the host that runs the worker and returns its trimmed stdout and stderr.

1. Resolves the config. `command`, `cwd` and `timeout` (default 10000 ms) fall back to the same keys of the incoming payload.
2. Fails through `error` when `command` is empty.
3. Runs `command` in a shell, in `cwd` (default: the working directory of the orchestrator process), and stops it after `timeout` ms.
4. Exit code 0 leaves through `out` with `{ stdout, stderr }` trimmed; a non-zero exit, a timeout or a launch failure leaves through `error` with the untrimmed output.

## In a workflow

### Node

```json
{
  "node_id": "node-list-exports",
  "label": "List exports",
  "operator_slug": "io.local.shell",
  "operator_version": "1.0.0",
  "config": {
    "command": "ls /data/exports | grep orders",
    "cwd": "/data",
    "timeout": 10000
  }
}
```

### Envelope

```json
{
  "ok": true,
  "data": {
    "stdout": "orders-2026-11-25.csv\norders-2026-11-26.csv",
    "stderr": ""
  },
  "port": "out"
}
```

## Output ports (behaviour in the code)

### `out`

The command exited with code 0.

```json
{
  "stdout": "orders-2026-11-25.csv\norders-2026-11-26.csv",
  "stderr": ""
}
```

### `error`

The command exited non-zero, timed out, exceeded the output buffer or could not start. Data is `{ error, stderr, stdout }`; for a missing `command`, only `{ error }`.

```json
{
  "error": "Command failed: ls /data/missing\nls: /data/missing: No such file or directory\n",
  "stderr": "ls: /data/missing: No such file or directory\n",
  "stdout": ""
}
```

## Behaviour in the code

- `command`: Interpreted by the shell: pipes, redirections and `&&` work, and values inserted with expressions become part of the command line. To pass data from upstream nodes as arguments, prefer `code.shell`, which runs a program with an argument list and no shell.

## Errors

| Message | Port | Cause and fix |
| --- | --- | --- |
| `command is required` | `error` | No command in the config nor in the incoming payload. |
| `Command failed: <command>
<stderr>` | `error` | The command exited non-zero or was stopped after `timeout` ms. Read `stderr` for the reason; raise `timeout` for long commands. |
| `stdout maxBuffer length exceeded` | `error` | The command wrote more than about 1 MB to stdout or stderr. Write large output to a file and read it with `io.local.file`. |

## Notes and limits

- The exit code is not included in the output; `out` means exit code 0.
- The command runs on the host or container of the orchestrator worker, with that process's user and permissions.


## Contracts (JSON Schema)

### All (`*.definition.js`)

```json
{
  "slug": "io.local.shell",
  "name": "Local Shell Command",
  "category": "io",
  "version": "1.0.0",
  "description": "Execute shell command on the host machine.",
  "capabilities": [
    "shell",
    "local",
    "terminal"
  ],
  "config_schema": {
    "type": "object",
    "properties": {
      "command": {
        "type": "string",
        "description": "Command to execute"
      },
      "cwd": {
        "type": "string",
        "description": "Current Working Directory"
      },
      "timeout": {
        "type": "number",
        "default": 10000
      }
    },
    "required": [
      "command"
    ]
  },
  "input_contract_schema": {
    "type": "object",
    "properties": {
      "command": {
        "type": "string"
      },
      "cwd": {
        "type": "string"
      },
      "timeout": {
        "type": "number"
      }
    },
    "required": [
      "command"
    ]
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "stdout": {
        "type": "string"
      },
      "stderr": {
        "type": "string"
      }
    }
  },
  "ports": [
    {
      "port_id": "out",
      "label": "Output",
      "description": "Command executed successfully",
      "is_default": true,
      "supports_condition": true
    },
    {
      "port_id": "error",
      "label": "Error",
      "description": "Command returned non-zero exit code or failed",
      "is_default": false,
      "supports_condition": false
    }
  ],
  "execution_mode": "async",
  "required_resources": [],
  "compatible_worker_pools": [
    "desktop-agent",
    "local-agent"
  ],
  "tags": [
    "local",
    "terminal"
  ],
  "is_stateful": false,
  "publisher": {
    "identity": "org_link_loom",
    "profile": {
      "name": "Link Loom",
      "verified": true,
      "url": "https://me.veripass.com/link-loom",
      "logo_url": null
    }
  }
}
```

### config_schema

```json
{
  "type": "object",
  "properties": {
    "command": {
      "type": "string",
      "description": "Command to execute"
    },
    "cwd": {
      "type": "string",
      "description": "Current Working Directory"
    },
    "timeout": {
      "type": "number",
      "default": 10000
    }
  },
  "required": [
    "command"
  ]
}
```

### input_contract_schema

```json
{
  "type": "object",
  "properties": {
    "command": {
      "type": "string"
    },
    "cwd": {
      "type": "string"
    },
    "timeout": {
      "type": "number"
    }
  },
  "required": [
    "command"
  ]
}
```

### output_contract_schema

```json
{
  "type": "object",
  "properties": {
    "stdout": {
      "type": "string"
    },
    "stderr": {
      "type": "string"
    }
  }
}
```

### ports

```json
[
  {
    "port_id": "out",
    "label": "Output",
    "description": "Command executed successfully",
    "is_default": true,
    "supports_condition": true
  },
  {
    "port_id": "error",
    "label": "Error",
    "description": "Command returned non-zero exit code or failed",
    "is_default": false,
    "supports_condition": false
  }
]
```
