nebulaflow

CLI Nodes (Shell Nodes)

CLI nodes, also called Shell nodes, allow you to execute shell commands and scripts within your workflows. These nodes support streaming output, user approval, safety levels, and advanced configuration for stdin, environment variables, and shell flags.

Configuration

Mode

Command / Script Content

Shell Selection

Safety Level

Stream Output

Stdin Configuration (Script Mode)

Environment Mapping (Script Mode)

Shell Flags

Bash/Sh/Zsh Flags

PowerShell Flags

Approval & Safety

Input/Output

Inputs

Outputs

Variable Usage

Template Variables

Use positional inputs in the command/script:

echo "Processing ${1} and ${2}"

Environment Variables

In script mode, you can expose parent outputs as environment variables:

# With exposeParents enabled and names: SRC, DEST
cp "$SRC" "$DEST"

Static Environment

Define static environment variables in JSON:

{
  "DEBUG": "true",
  "LOG_LEVEL": "info"
}

Examples

Basic Command

echo "Hello, World!"

Using Parent Output

echo "Received: ${1}"

Script with Stdin

File Processing

cat input.txt | grep "error" | wc -l

PowerShell Script

Safe Command with Approval

Best Practices

Security

  1. Use Safe Mode: Keep safety level as “safe” unless absolutely necessary.
  2. Review Commands: Enable user approval for any command that modifies files or systems.
  3. Avoid Dangerous Patterns: Don’t use rm -rf, sudo, dd, etc. in safe mode.
  4. Sanitize Inputs: Validate and sanitize any user-provided data before using in commands.

Error Handling

  1. Check Exit Codes: Use condition nodes to check CLI exit codes.
  2. Abort on Error: Enable for critical commands where failure should stop the workflow.
  3. Log Errors: Capture stderr and log for debugging.
  4. Retry Logic: Implement retries for transient failures (e.g., network commands).

Performance

  1. Use Spawn for Long Commands: Enable stream output for commands that produce large output.
  2. Batch Operations: Combine multiple commands into a single script when possible.
  3. Avoid Unnecessary Pipes: Each pipe adds overhead; consider using built-in shell features.
  4. Cache Results: Store frequently used outputs in variables.

Scripting Tips

  1. Use Explicit Shebang: In script mode, you can include a shebang line (e.g., #!/bin/bash) for clarity.
  2. Quote Variables: Always quote variables to handle spaces and special characters.
  3. Set Shell Flags: Use set -e -u -o pipefail for robust scripts.
  4. Handle Windows Paths: Use pwsh on Windows for better path handling.

Troubleshooting

Command Not Found

Permission Denied

Timeout Errors

Stdin Issues

Environment Variables Not Set

Approval Not Working

Shell Flags Not Applied

Exit Code Not Captured

Integration with Other Nodes

Before CLI

After CLI

Common Patterns

Configuration Example

cli_node:
  title: "File List"
  mode: "command"
  content: "ls -la ${1}"
  shell: "bash"
  safetyLevel: "safe"
  streamOutput: true
  needsUserApproval: false
  shouldAbort: true
  stdin:
    source: "none"
  env:
    exposeParents: false
    names: []
    static: {}
  flags:
    exitOnError: true
    unsetVars: true
    pipefail: false

Next Steps