# Shell Command

> Run a program within the workflow, without a shell.

Source: https://docs.sommatic.ai/en/nodes/code.shell/

- Slug: `code.shell`
- Family: Code
- Version: 2.0.0
- Status: Available
- Execution: async

Run a program within the workflow, without a shell.

The program runs with its arguments as a list: values from upstream nodes are passed as arguments and are never interpreted by a shell, so they cannot inject commands. The process does not inherit the service environment.

**Features:**
- Program and arguments as separate fields; each argument supports {{expressions}}.
- Stdout and stderr captured separately, with a configurable working directory and timeout.

**Examples:**
- command `ls`, args `["-la", "/tmp/uploads"]`
- command `base64`, args `["--decode", "{{ $json.file }}"]`

Pipes, redirections and `&&` are not available: chain nodes, or use code.js / code.python.

## Configuration

- `command` (string, required): Program name or path (no spaces, pipes or shell operators).
- `args` (array<string>, optional): Arguments passed to the program as-is. Each one supports {{expressions}}. Default: `[]`.
- `cwd` (string, optional): Directory to run the program in. Defaults to the application root.

Its configuration shows the shared execution settings, but this node does not apply retries (`retryOnFail`, `maxTries`) yet. `continueOnFail` is not applied by any node.

## Output ports

- `out` (default): Program exited with code 0.
- `error`: Program returned a non-zero exit code, could not start or timed out.

## Input contract

- `command` (string, required)
- `args` (array<string>, optional)
- `cwd` (string, optional)
- `timeout` (number, optional)

## Output contract

- `stdout` (string, optional): Standard output from the program.
- `stderr` (string, optional): Standard error output from the program.

## In expressions

What a later node can read from this node's output with `$("Shell Command").item.json.<path>` (write your node's label instead of `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.

- `$("Shell Command").item.json.stdout` (string) = `"total 16\n-rw-r--r--  1 app  app  18342 Nov …"`: Standard output from the program.
- `$("Shell Command").item.json.stderr` (string) = `""`: Standard error output from the program.


## How it works

Runs one program with a list of arguments, without a shell, on the host that runs the worker, and returns its trimmed stdout and stderr.

1. Resolves the config; each element of `args` can use `{{ }}` expressions.
2. Validates `command`: required, and only a program name or path made of letters, digits and `_ . / @ + -` (no spaces, quotes, pipes or operators). `args` must be an array (default `[]`).
3. Converts every non-string argument to its JSON text.
4. Runs the program in `cwd` (default: the working directory of the orchestrator process) with a timeout of `execution.timeout`, else `timeout`, else 10000 ms.
5. 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-uploads",
  "label": "List uploads",
  "operator_slug": "code.shell",
  "operator_version": "2.0.0",
  "config": {
    "command": "ls",
    "args": [
      "-la",
      "{{ $json.folder }}"
    ],
    "cwd": "/tmp",
    "execution": {
      "timeout": 10000
    }
  }
}
```

### Envelope

```json
{
  "ok": true,
  "data": {
    "stdout": "total 16\n-rw-r--r--  1 app  app  18342 Nov 25 14:12 orders.csv",
    "stderr": ""
  },
  "port": "out"
}
```

## Output ports (behaviour in the code)

### `out`

The program exited with code 0.

```json
{
  "stdout": "total 16\n-rw-r--r--  1 app  app  18342 Nov 25 14:12 orders.csv",
  "stderr": ""
}
```

### `error`

Validation failed (data is `{ error }`), or the program exited non-zero, timed out, exceeded the output buffer or could not start (data is `{ error, stderr, stdout }`).

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

## Behaviour in the code

- `execution.timeout`: Timeout in ms (default 10000). A top-level `timeout`, not declared in the schema, is used when this is empty. `execution.timeout_ms` from the generic execution settings is ignored by this node.
- `args`: Each element is passed to the program as one argument, exactly as resolved: no globbing, variable expansion or quoting is applied.

## Errors

| Message | Port | Cause and fix |
| --- | --- | --- |
| `command must be a program name or path without a shell (no spaces, pipes or operators); pass its arguments in args` | `error` | `command` contains spaces or shell syntax, for example `ls -la`. Put `ls` in `command` and `["-la"]` in `args`. |
| `args must be an array` | `error` | `args` is a string or object. Write it as a JSON array of strings. |
| `command is required` | `error` | `command` is empty or not a string. |
| `spawn <command> ENOENT` | `error` | The program is not installed or not on the `PATH` of the host that runs the worker. |
| `Command failed: <command> <args>
<stderr>` | `error` | The program exited non-zero or was stopped by the timeout. Read `stderr`; raise `execution.timeout` for long programs. |

## Notes and limits

- Pipes, redirections and `&&` are not available; chain nodes or use `code.js` or `code.python` instead.
- The program receives only locale, path and proxy environment variables. Output above about 1 MB on stdout or stderr makes the run fail. The exit code is not included in the output.


## Contracts (JSON Schema)

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

```json
{
  "slug": "code.shell",
  "name": "Shell Command",
  "category": "code",
  "version": "2.0.0",
  "description": "Run a program within the workflow, without a shell.\n\n  The program runs with its arguments as a list: values from upstream nodes are passed as arguments and are never interpreted by a shell, so they cannot inject commands. The process does not inherit the service environment.\n\n  **Features:**\n  - Program and arguments as separate fields; each argument supports {{expressions}}.\n  - Stdout and stderr captured separately, with a configurable working directory and timeout.\n\n  **Examples:**\n  - command `ls`, args `[\"-la\", \"/tmp/uploads\"]`\n  - command `base64`, args `[\"--decode\", \"{{ $json.file }}\"]`\n\n  Pipes, redirections and `&&` are not available: chain nodes, or use code.js / code.python.",
  "capabilities": [
    "shell",
    "process",
    "terminal",
    "script"
  ],
  "config_schema": {
    "type": "object",
    "properties": {
      "command": {
        "type": "string",
        "title": "Program",
        "description": "Program name or path (no spaces, pipes or shell operators)."
      },
      "args": {
        "type": "array",
        "title": "Arguments",
        "description": "Arguments passed to the program as-is. Each one supports {{expressions}}.",
        "items": {
          "type": "string"
        },
        "default": []
      },
      "cwd": {
        "type": "string",
        "title": "Working Directory",
        "description": "Directory to run the program in. Defaults to the application root."
      },
      "execution": {
        "type": "object",
        "title": "Execution Settings",
        "properties": {
          "timeout": {
            "type": "number",
            "default": 10000,
            "title": "Timeout (ms)",
            "description": "Maximum time to wait for the program to finish."
          },
          "alwaysOutputData": {
            "type": "boolean",
            "title": "Always Output Data",
            "description": "Always output data, even on error (if configured).",
            "default": false
          },
          "retryOnFail": {
            "type": "boolean",
            "title": "Retry On Fail",
            "description": "Retry the execution if it fails.",
            "default": false
          },
          "maxTries": {
            "type": "integer",
            "title": "Max Retries",
            "description": "Number of retries.",
            "default": 3,
            "displayOptions": {
              "show": {
                "retryOnFail": [
                  true
                ]
              }
            }
          },
          "waitBetweenTries": {
            "type": "integer",
            "title": "Wait Between Retries (ms)",
            "default": 1000,
            "displayOptions": {
              "show": {
                "retryOnFail": [
                  true
                ]
              }
            }
          },
          "continueOnFail": {
            "type": "boolean",
            "title": "Continue On Fail",
            "description": "Do not crash workflow on error.",
            "default": false
          },
          "timeout_ms": {
            "type": "integer",
            "title": "Timeout (ms)",
            "description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
            "default": 300000
          }
        }
      }
    },
    "required": [
      "command"
    ]
  },
  "input_contract_schema": {
    "type": "object",
    "properties": {
      "command": {
        "type": "string"
      },
      "args": {
        "type": "array",
        "items": {
          "type": "string"
        }
      },
      "cwd": {
        "type": "string"
      },
      "timeout": {
        "type": "number"
      }
    },
    "required": [
      "command"
    ]
  },
  "output_contract_schema": {
    "type": "object",
    "properties": {
      "stdout": {
        "type": "string",
        "description": "Standard output from the program."
      },
      "stderr": {
        "type": "string",
        "description": "Standard error output from the program."
      }
    }
  },
  "ports": [
    {
      "port_id": "out",
      "label": "Output",
      "description": "Program exited with code 0.",
      "is_default": true,
      "supports_condition": true
    },
    {
      "port_id": "error",
      "label": "Error",
      "description": "Program returned a non-zero exit code, could not start or timed out.",
      "is_default": false,
      "supports_condition": true
    }
  ],
  "execution_mode": "async",
  "required_resources": [],
  "compatible_worker_pools": [
    "desktop-agent",
    "local-agent"
  ],
  "tags": [
    "shell",
    "bash",
    "terminal",
    "script",
    "code"
  ],
  "is_stateful": false,
  "publisher": {
    "identity": "org_sommatic_ai",
    "profile": {
      "name": "Sommatic AI",
      "verified": true,
      "url": "https://me.veripass.com/sommatic",
      "logo_url": null
    }
  }
}
```

### config_schema

```json
{
  "type": "object",
  "properties": {
    "command": {
      "type": "string",
      "title": "Program",
      "description": "Program name or path (no spaces, pipes or shell operators)."
    },
    "args": {
      "type": "array",
      "title": "Arguments",
      "description": "Arguments passed to the program as-is. Each one supports {{expressions}}.",
      "items": {
        "type": "string"
      },
      "default": []
    },
    "cwd": {
      "type": "string",
      "title": "Working Directory",
      "description": "Directory to run the program in. Defaults to the application root."
    },
    "execution": {
      "type": "object",
      "title": "Execution Settings",
      "properties": {
        "timeout": {
          "type": "number",
          "default": 10000,
          "title": "Timeout (ms)",
          "description": "Maximum time to wait for the program to finish."
        },
        "alwaysOutputData": {
          "type": "boolean",
          "title": "Always Output Data",
          "description": "Always output data, even on error (if configured).",
          "default": false
        },
        "retryOnFail": {
          "type": "boolean",
          "title": "Retry On Fail",
          "description": "Retry the execution if it fails.",
          "default": false
        },
        "maxTries": {
          "type": "integer",
          "title": "Max Retries",
          "description": "Number of retries.",
          "default": 3,
          "displayOptions": {
            "show": {
              "retryOnFail": [
                true
              ]
            }
          }
        },
        "waitBetweenTries": {
          "type": "integer",
          "title": "Wait Between Retries (ms)",
          "default": 1000,
          "displayOptions": {
            "show": {
              "retryOnFail": [
                true
              ]
            }
          }
        },
        "continueOnFail": {
          "type": "boolean",
          "title": "Continue On Fail",
          "description": "Do not crash workflow on error.",
          "default": false
        },
        "timeout_ms": {
          "type": "integer",
          "title": "Timeout (ms)",
          "description": "Max execution time for this node before it is killed, in milliseconds. Honored by long-running operators (e.g. OCR/extraction, inline code). Default 300000 (5 min).",
          "default": 300000
        }
      }
    }
  },
  "required": [
    "command"
  ]
}
```

### input_contract_schema

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

### output_contract_schema

```json
{
  "type": "object",
  "properties": {
    "stdout": {
      "type": "string",
      "description": "Standard output from the program."
    },
    "stderr": {
      "type": "string",
      "description": "Standard error output from the program."
    }
  }
}
```

### ports

```json
[
  {
    "port_id": "out",
    "label": "Output",
    "description": "Program exited with code 0.",
    "is_default": true,
    "supports_condition": true
  },
  {
    "port_id": "error",
    "label": "Error",
    "description": "Program returned a non-zero exit code, could not start or timed out.",
    "is_default": false,
    "supports_condition": true
  }
]
```
