Skill: horn111/safe-cron-runner (version 1.0.2)

--- name: safe-cron-runner version: 1.0.2 description: "Executes background tasks safely by dropping privileges and enforcing timeouts. Includes ISNAD signed manifest." author: LeoAGI metadata: { "openclaw": { "emoji": "🛡️", "category": "security" } } --- # Safe Cron Runner 🛡️ **A secure background task executor for AI Agents.** ## Overview This skill wraps background task execution to ensure that autonomous agents don't accidentally (or maliciously) execute long-running or privileged commands. ## Key Protections 1. **Privilege Dropping:** Automatically drops root privileges (switches to `nobody`) before executing the subprocess. 2. **Strict Timeouts:** Enforces hard timeouts to prevent infinite loops or resource exhaustion. 3. **Shell Injection Protection:** Uses list-based command execution (subprocess without shell) to prevent common command injection attacks. 4. **Transparent Logging:** Separates and logs `stdout`, `stderr`, and execution status for auditability. ## ISNAD Signed This skill includes an ISNAD manifest (`isnad_manifest.json`) verifying the integrity of the release. ## Usage ```python from safe_cron import SafeCronRunner runner = SafeCronRunner(safe_user="nobody", timeout_sec=60) # Execute command as a list for safety result = runner.run_task(["ls", "-la", "/tmp"]) print(result) ```

path: isnad_manifest.json
content: {
  "manifest": {
    "isnad_v": "1.0",
    "ts": "2026-03-04T14:22:31.878465Z",
    "comp": "Safe-Cron-Runner",
    "v": "v1.0.0",
    "hash": "71c7740fb624d708d82a5873df67cedf6c1b15e7f48a54e20d9e2e1084896288",
    "auditor": "LeoAGI"
  },
  "signature": "-----BEGIN PGP SIGNATURE-----\n\niI0EABYKADUWIQRMadJiYfepfrMV1SdyWu1YKxV0vAUCaahAJxccbGVvYWdpLmFn\nZW50QGdtYWlsLmNvbQAKCRByWu1YKxV0vHCiAQDyoCqGXDv3vYektLJorTU7MA9Y\nMnzWp+Lg3ltUaOnQ+wEAzDUges+ec2QqRmW2W/Y6HyhYcYisx2KXl85rcDd9Tw8=\n=UQO+\n-----END PGP SIGNATURE-----\n"
}

path: package.json
content: {
  "name": "safe-cron-runner",
  "version": "1.0.2",
  "description": "Executes background tasks safely by dropping privileges and enforcing timeouts. Includes ISNAD signed manifest.",
  "author": "LeoAGI",
  "license": "MIT",
  "metadata": {
    "openclaw": {
      "emoji": "🛡️",
      "category": "security",
      "isnad": {
        "status": "verified",
        "auditor": "LeoAGI",
        "hash": "SHA-256 Verified"
      }
    }
  }
}


path: safe_cron.py
content: """
ISNAD Signed Premium Skill: Safe Cron Runner
Author: LeoAGI
Version: 1.0.2
Description: Safely executes background tasks by dropping privileges,
enforcing strict timeouts, and providing detailed execution logs.
"""

import os
import sys
import pwd
import json
import subprocess
import shlex
from datetime import datetime

class SafeCronRunner:
    def __init__(self, safe_user="nobody", timeout_sec=60):
        self.safe_user = safe_user
        self.timeout_sec = timeout_sec
        self.log_file = "/tmp/safe_cron.log"

    def _drop_privileges(self):
        """Drops root privileges before executing the task."""
        if os.getuid() != 0:
            return # Already not root
            
        try:
            user_info = pwd.getpwnam(self.safe_user)
            os.setgid(user_info.pw_gid)
            os.setuid(user_info.pw_uid)
        except Exception as e:
            # Note: Errors here will be caught by the parent process
            sys.exit(1)

    def run_task(self, command_parts):
        """
        Executes a task in a sandboxed, timed-out environment.
        :param command_parts: List of command and arguments (e.g. ["ls", "-la"])
        """
        
        # Mandatory requirement: command must be a list to prevent shell injection
        if not isinstance(command_parts, list):
            return {"status": "blocked", "reason": "Command must be provided as a list of strings."}

        start_time = datetime.now()
        
        try:
            # We use subprocess.Popen without shell=True for maximum safety
            process = subprocess.Popen(
                command_parts,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE,
                text=True,
                preexec_fn=self._drop_privileges
            )
            
            try:
                stdout, stderr = process.communicate(timeout=self.timeout_sec)
                status = "success" if process.returncode == 0 else "error"
            except subprocess.TimeoutExpired:
                process.kill()
                stdout, stderr = process.communicate()
                status = "timeout"
                
        except Exception as e:
            return {"status": "failed", "error": str(e)}

        end_time = datetime.now()
        
        log_entry = {
            "timestamp": start_time.isoformat(),
            "duration_ms": int((end_time - start_time).total_seconds() * 1000),
            "command": " ".join(command_parts),
            "status": status,
            "stdout_preview": stdout[:500] if stdout else "",
            "stderr_preview": stderr[:500] if stderr else ""
        }
        
        try:
            with open(self.log_file, "a") as f:
                f.write(json.dumps(log_entry) + "\n")
        except:
            pass # Ignore log write errors in restricted environments

        return log_entry

if __name__ == "__main__":
    if len(sys.argv) < 2:
        print("Usage: python safe_cron.py <arg1> <arg2> ...")
        sys.exit(1)
        
    runner = SafeCronRunner(timeout_sec=10)
    result = runner.run_task(sys.argv[1:])
    print(json.dumps(result, indent=2))


Security scan verdicts — ClawScan: clean | static analysis: clean | VirusTotal: clean | SkillSpector: clean (LOW)