@badc0d3/piece-bash-runner
v1.2.0
Published
Run bash commands with NFS/SMB mounting support in Activepieces
Downloads
38
Maintainers
Readme
Bash Command Runner for Activepieces
Execute bash commands and scripts with support for mounting NFS and SMB network drives in your Activepieces workflows.
Features
- 🖥️ Execute Bash Commands: Run any bash command or script
- 📁 Network Drive Support: Mount NFS and SMB/CIFS drives before executing commands
- 🔒 Two Execution Modes:
- Standard: Direct execution with mount privileges
- Sandboxed: Docker-based execution with resource limits
- 🔑 Authentication Support: Username/password for SMB shares
- ⚡ Flexible Configuration: Custom mount options and working directories
- 📊 Output Capture: Separate stdout/stderr capture
Installation
NPM
npm install @badc0d3/piece-bash-runnerIn Activepieces
- Copy the piece to your Activepieces pieces directory
- Restart your Activepieces instance
- The Bash Command Runner will be available in your flows
Usage
Basic Command Execution
#!/bin/bash
echo "Hello from Bash!"
ls -la
pwdMount NFS Drive and Process Files
#!/bin/bash
# Files will be available at /mnt/network after mounting
find /mnt/network -name "*.txt" -exec wc -l {} +Mount Configuration:
- Type: NFS
- Source:
server.local:/exports/data - Mount Point:
/mnt/network - Options:
rw,sync
Mount SMB Share with Authentication
#!/bin/bash
# Copy files from SMB share
cp -r /mnt/network/documents /tmp/backup/Mount Configuration:
- Type: SMB/CIFS
- Source:
//server.local/share - Mount Point:
/mnt/network - Username:
myuser - Password:
[use secure text]
Actions
Run Bash Command (Standard)
Executes bash commands directly on the host system.
Properties:
- Bash Command: The command or script to execute
- Mount Configuration: Optional NFS/SMB mount settings
- Working Directory: Directory to execute commands in
- Timeout: Maximum execution time
- Capture Output: Whether to capture stdout/stderr separately
Requirements:
- For NFS:
nfs-commonpackage installed - For SMB:
cifs-utilspackage installed - Mount privileges (may require root or sudo)
Run Bash Command (Sandboxed)
Executes bash commands in a Docker container with automatic installation of mount utilities.
Properties:
- Bash Command: The command or script to execute
- Mount Configuration: Optional NFS/SMB mount settings
- Docker Image: Base image to use (default: ubuntu:latest)
- Timeout: Maximum execution time
- Run as Root: Toggle to run commands as root user (default: false, less secure)
Security Features:
- Privileged operations (mounting) run as root
- User commands run as non-root user (
activepiecesUID/GID 1001) without sudo access by default - Option to run commands as root when explicitly needed
- Proper privilege separation between system operations and user code
- Resource limits (512MB RAM, 50% CPU)
- Automatic cleanup after execution
Required Permissions:
- Docker socket access:
-v /var/run/docker.sock:/var/run/docker.sock - Container runs with
SYS_ADMINcapability for mounting
Mount Configuration
NFS Options
Common NFS mount options:
rw: Read-write accessro: Read-only accesssync: Synchronous writesasync: Asynchronous writesnolock: Disable file lockingvers=3orvers=4: NFS version
SMB/CIFS Options
Common SMB mount options:
rw: Read-write accessro: Read-only accessvers=1.0,vers=2.0,vers=3.0: SMB protocol versiondomain=WORKGROUP: Domain nameuid=1000: User ID for file ownershipgid=1000: Group ID for file ownership
Security Considerations
Standard Version
- Runs with the same privileges as Activepieces
- Mount operations may require elevated privileges
- Consider using restricted mount options
Sandboxed Version
- Runs in Docker container with limited resources
- Mounting operations performed as root for security
- User commands execute as non-root user without sudo privileges
- Container has
SYS_ADMINcapability for mounting - Proper privilege separation ensures user code cannot perform system operations
- Isolated from host system
Best Practices
- Use read-only mounts when possible (
rooption) - Store credentials securely using Activepieces secure text
- Unmount drives after use (handled automatically)
- Validate and sanitize file paths
- Use specific mount options to limit access
Examples
Backup Files from NFS
#!/bin/bash
# Create backup directory
mkdir -p /tmp/backup/$(date +%Y%m%d)
# Copy files from NFS mount
rsync -av /mnt/network/important/ /tmp/backup/$(date +%Y%m%d)/
# Create archive
tar -czf /tmp/backup-$(date +%Y%m%d).tar.gz /tmp/backup/$(date +%Y%m%d)/
echo "Backup completed successfully"Process CSV Files from SMB Share
#!/bin/bash
# Find all CSV files
for file in /mnt/network/data/*.csv; do
echo "Processing: $file"
# Count lines
lines=$(wc -l < "$file")
echo "Lines: $lines"
# Get first line (headers)
head -1 "$file"
echo "---"
doneSystem Monitoring Script
#!/bin/bash
# No mount needed for system monitoring
echo "=== System Information ==="
echo "Hostname: $(hostname)"
echo "Uptime: $(uptime)"
echo ""
echo "=== Disk Usage ==="
df -h
echo ""
echo "=== Memory Usage ==="
free -hRunning Commands as Root (When Needed)
For operations that require root privileges, enable the "Run as Root" option:
#!/bin/bash
# Example: Installing system packages (requires root)
apt-get update
apt-get install -y htop iotop
# Example: Modifying system files
echo "192.168.1.100 myserver.local" >> /etc/hosts
# Example: System administration tasks
systemctl status dockerNote: Running as root should only be used when absolutely necessary. The default non-root execution provides better security.
Troubleshooting
Mount Permission Denied
- Ensure the user has mount privileges
- For Docker, ensure
SYS_ADMINcapability is granted - Check AppArmor/SELinux policies
NFS Mount Fails
- Verify NFS server is accessible:
showmount -e server - Check firewall rules (port 2049 for NFS)
- Try different NFS versions:
vers=3orvers=4
SMB Mount Fails
- Verify SMB share is accessible:
smbclient -L //server - Check credentials and escape special characters
- Try different SMB versions:
vers=1.0,vers=2.0,vers=3.0
Docker Socket Error
- Mount Docker socket:
-v /var/run/docker.sock:/var/run/docker.sock - Ensure Docker is running
- Check Docker permissions
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
MIT
