Skip to content

synergyboat/n8n-shell-commands-executor

Repository files navigation

n8n-nodes-command-executor

This is an n8n community node that allows you to execute shell commands on self-hosted n8n instances.

n8n is a fair-code licensed workflow automation platform.

⚠️ Security Warning

IMPORTANT: This node executes arbitrary commands on your server. It should ONLY be used on self-hosted n8n instances that you control. Never use this node if you don't understand the security implications.

  • Commands run with the same permissions as your n8n process
  • Malicious commands could damage your system or compromise security
  • Always validate and sanitize inputs when using generic command mode
  • Consider using templates for common operations to reduce risk

Installation

Follow the installation guide in the n8n community nodes documentation.

NPM

npm install n8n-nodes-command-executor

Manual Installation (Development)

  1. Clone this repository
  2. Run npm install to install dependencies
  3. Run npm run build to build the node
  4. Copy the built files to your n8n custom nodes directory

Operations

The Command Executor node supports two modes:

Generic Command Mode

Execute any shell command you specify. This mode gives you complete flexibility but requires careful attention to security.

Example:

echo "Hello from n8n!"

Template Mode

Use pre-configured command templates with safe, parameterized inputs. This is the recommended mode for most use cases.

Available Templates

Template Description Parameters
System Information Get OS info, disk usage, and memory None
List Files List files in a directory Path, Options
Read File Read file contents File Path
Find Files Find files matching a pattern Search Path, Pattern
Process List List running processes Filter (optional)
Network Ping Ping a host Host, Count
HTTP Request (curl) Make HTTP requests with curl URL, Options
Disk Usage Show disk usage for a path Path
Execute Python Code Run Python code or script files Execution Mode, Interpreter, Code/File Path, Arguments
Execute Node.js Code Run JavaScript code or script files Execution Mode, Code/File Path, Arguments

Configuration

Common Options

  • Working Directory: Set the working directory for command execution
  • Timeout: Maximum execution time in seconds (1-300, default: 30)
  • Environment Variables: Add custom environment variables for your command
  • Continue on Error: If enabled, the workflow continues even if the command fails

Output

The node returns the following data for each execution:

{
  "command": "echo 'test'",
  "exitCode": 0,
  "stdout": "test\n",
  "stderr": "",
  "executionTimeMs": 45,
  "success": true
}

Usage Examples

Example 1: System Information

Use the "System Information" template to get details about your server:

  1. Add Command Executor node
  2. Select Mode: "Template"
  3. Select Template: "System Information"
  4. Run the workflow

Example 2: List Files

List all files in a directory with details:

  1. Add Command Executor node
  2. Select Mode: "Template"
  3. Select Template: "List Files"
  4. Path: /var/log
  5. Options: "Long format with hidden files (-lah)"

Example 3: Generic Command

Execute a custom command:

  1. Add Command Executor node
  2. Select Mode: "Generic Command"
  3. Command: df -h | grep /dev/
  4. Run the workflow

Example 4: Backup Database

Use generic mode to backup a database:

mysqldump -u root -p'password' mydb > /backups/mydb_$(date +%Y%m%d).sql

⚠️ Security Note: Never hardcode sensitive credentials. Use environment variables or n8n credentials instead.

Example 5: Execute Python Code

Run Python code inline:

  1. Add Command Executor node
  2. Select Mode: "Template"
  3. Select Template: "Execute Python Code"
  4. Execution Mode: "Inline Code"
  5. Python Interpreter: "Python 3"
  6. Code: import sys; print(f"Python {sys.version}")
  7. Run the workflow

Or execute a Python script file:

  1. Execution Mode: "File Path"
  2. File Path: /path/to/script.py
  3. Arguments: --arg1 value1

Example 6: Execute Node.js Code

Run JavaScript code inline:

  1. Add Command Executor node
  2. Select Mode: "Template"
  3. Select Template: "Execute Node.js Code"
  4. Execution Mode: "Inline Code"
  5. Code: console.log(process.version); console.log("Hello from Node!")
  6. Run the workflow

Or execute a JavaScript file:

  1. Execution Mode: "File Path"
  2. File Path: /path/to/script.js
  3. Arguments: --experimental-modules

Development

Setup

git clone https://github.com/your-repo/n8n-nodes-command-executor.git
cd n8n-nodes-command-executor
npm install

Build

npm run build

Run in Development Mode

npm run dev

This will start n8n with your node loaded and watch for changes.

Lint

npm run lint
npm run lint:fix

Compatibility

  • Tested with n8n v1.0+
  • Compatible with Node.js v20+

Resources

License

MIT

Version History

0.1.0

  • Initial release
  • Generic command execution
  • 10 pre-configured templates (including Python and Node.js code execution)
  • Environment variable support
  • Configurable timeouts and working directory

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Support

If you have any issues or questions, please open an issue on GitHub or ask in the n8n community forum.

Disclaimer

This node is provided as-is with no warranties. Use at your own risk. The authors are not responsible for any damage or security issues that may arise from using this node.

About

This is an n8n community node that allows you to execute shell commands on self-hosted n8n instances.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors