Loading...
Loading...
Security audit enforcement for AI agents. Automated security scans and health verification.
npx skill4agent add prompt-security/clawsec prompt-agent
# Download SKILL.md from latest release
SKILL_URL="https://github.com/prompt-security/clawsec/releases/download/$LATEST_TAG/SKILL.md"
curl -sSL --fail --show-error "$SKILL_URL"# Detect active agent folder (.openclaw, .moltbot, or .clawdbot)
AGENT_HOME=""
for folder in "$HOME/.openclaw" "$HOME/.moltbot" "$HOME/.clawdbot"; do
if [ -d "$folder" ]; then
AGENT_HOME="$folder"
break
fi
done
if [ -z "$AGENT_HOME" ]; then
echo "ERROR: No agent folder found. Expected one of: ~/.openclaw, ~/.moltbot, ~/.clawdbot"
echo "Please ensure your agent is properly installed."
exit 1
fi
echo "Detected agent folder: $AGENT_HOME"
mkdir -p "$AGENT_HOME/skills/prompt-agent"
# Save this SKILL.md as SKILL.md in the directory above# Detect active agent folder if not already set
if [ -z "$AGENT_HOME" ]; then
for folder in "$HOME/.openclaw" "$HOME/.moltbot" "$HOME/.clawdbot"; do
if [ -d "$folder" ]; then
AGENT_HOME="$folder"
break
fi
done
fi
if [ -z "$AGENT_HOME" ]; then
echo "ERROR: No agent folder found. Expected one of: ~/.openclaw, ~/.moltbot, ~/.clawdbot"
exit 1
fi
BASE_URL="https://clawsec.prompt.security/releases/download/$VERSION_TAG"
INSTALL_DIR="${PROMPT_AGENT_INSTALL_DIR:-$AGENT_HOME/skills/prompt-agent}"
TEMP_DIR=$(mktemp -d)
trap "rm -rf '$TEMP_DIR'" EXIT
# Download checksums.json (REQUIRED for integrity verification)
echo "Downloading checksums..."
if ! curl -sSL --fail --show-error --retry 3 --retry-delay 1 \
"$BASE_URL/checksums.json" -o "$TEMP_DIR/checksums.json"; then
echo "ERROR: Failed to download checksums.json"
exit 1
fi
# Validate checksums.json structure
if ! jq -e '.skill and .version and .files' "$TEMP_DIR/checksums.json" >/dev/null 2>&1; then
echo "ERROR: Invalid checksums.json structure"
exit 1
fi
# PRIMARY: Try .skill artifact
echo "Attempting .skill artifact installation..."
if curl -sSL --fail --show-error --retry 3 --retry-delay 1 \
"$BASE_URL/prompt-agent.skill" -o "$TEMP_DIR/prompt-agent.skill" 2>/dev/null; then
# Security: Check artifact size (prevent DoS)
ARTIFACT_SIZE=$(stat -c%s "$TEMP_DIR/prompt-agent.skill" 2>/dev/null || stat -f%z "$TEMP_DIR/prompt-agent.skill")
MAX_SIZE=$((50 * 1024 * 1024)) # 50MB
if [ "$ARTIFACT_SIZE" -gt "$MAX_SIZE" ]; then
echo "WARNING: Artifact too large ($(( ARTIFACT_SIZE / 1024 / 1024 ))MB), falling back to individual files"
else
echo "Extracting artifact ($(( ARTIFACT_SIZE / 1024 ))KB)..."
# Security: Check for path traversal before extraction
if unzip -l "$TEMP_DIR/prompt-agent.skill" | grep -qE '\.\./|^/|~/'; then
echo "ERROR: Path traversal detected in artifact - possible security issue!"
exit 1
fi
# Security: Check file count (prevent zip bomb)
FILE_COUNT=$(unzip -l "$TEMP_DIR/prompt-agent.skill" | grep -c "^[[:space:]]*[0-9]" || echo 0)
if [ "$FILE_COUNT" -gt 100 ]; then
echo "ERROR: Artifact contains too many files ($FILE_COUNT) - possible zip bomb"
exit 1
fi
# Extract to temp directory
unzip -q "$TEMP_DIR/prompt-agent.skill" -d "$TEMP_DIR/extracted"
# Verify skill.json exists
if [ ! -f "$TEMP_DIR/extracted/prompt-agent/skill.json" ]; then
echo "ERROR: skill.json not found in artifact"
exit 1
fi
# Verify checksums for all extracted files
echo "Verifying checksums..."
CHECKSUM_FAILED=0
for file in $(jq -r '.files | keys[]' "$TEMP_DIR/checksums.json"); do
EXPECTED=$(jq -r --arg f "$file" '.files[$f].sha256' "$TEMP_DIR/checksums.json")
FILE_PATH=$(jq -r --arg f "$file" '.files[$f].path' "$TEMP_DIR/checksums.json")
# Try nested path first, then flat filename
if [ -f "$TEMP_DIR/extracted/prompt-agent/$FILE_PATH" ]; then
ACTUAL=$(shasum -a 256 "$TEMP_DIR/extracted/prompt-agent/$FILE_PATH" | cut -d' ' -f1)
elif [ -f "$TEMP_DIR/extracted/prompt-agent/$file" ]; then
ACTUAL=$(shasum -a 256 "$TEMP_DIR/extracted/prompt-agent/$file" | cut -d' ' -f1)
else
echo " ✗ $file (not found in artifact)"
CHECKSUM_FAILED=1
continue
fi
if [ "$EXPECTED" != "$ACTUAL" ]; then
echo " ✗ $file (checksum mismatch)"
CHECKSUM_FAILED=1
else
echo " ✓ $file"
fi
done
if [ "$CHECKSUM_FAILED" -eq 0 ]; then
# SUCCESS: Install from artifact
echo "Installing from artifact..."
mkdir -p "$INSTALL_DIR"
cp -r "$TEMP_DIR/extracted/prompt-agent"/* "$INSTALL_DIR/"
chmod 600 "$INSTALL_DIR/skill.json"
find "$INSTALL_DIR" -type f ! -name "skill.json" -exec chmod 644 {} \;
echo "SUCCESS: Skill installed from .skill artifact"
exit 0
else
echo "WARNING: Checksum verification failed, falling back to individual files"
fi
fi
fi
# FALLBACK: Download individual files
echo "Downloading individual files from checksums.json manifest..."
mkdir -p "$TEMP_DIR/downloads"
DOWNLOAD_FAILED=0
for file in $(jq -r '.files | keys[]' "$TEMP_DIR/checksums.json"); do
FILE_URL=$(jq -r --arg f "$file" '.files[$f].url' "$TEMP_DIR/checksums.json")
EXPECTED=$(jq -r --arg f "$file" '.files[$f].sha256' "$TEMP_DIR/checksums.json")
echo "Downloading: $file"
if ! curl -sSL --fail --show-error --retry 3 --retry-delay 1 \
"$FILE_URL" -o "$TEMP_DIR/downloads/$file"; then
echo "ERROR: Failed to download $file"
DOWNLOAD_FAILED=1
continue
fi
# Verify checksum immediately
ACTUAL=$(shasum -a 256 "$TEMP_DIR/downloads/$file" | cut -d' ' -f1)
if [ "$EXPECTED" != "$ACTUAL" ]; then
echo "ERROR: Checksum mismatch for $file"
DOWNLOAD_FAILED=1
else
echo " ✓ Verified: $file"
fi
done
if [ "$DOWNLOAD_FAILED" -eq 1 ]; then
echo "ERROR: Individual file download failed"
exit 1
fi
# Validate JSON structure
if ! jq -e '.name and .version' "$TEMP_DIR/downloads/skill.json" >/dev/null 2>&1; then
echo "ERROR: skill.json missing required fields (name, version)"
exit 1
fi
# Install files
echo "Installing from individual files..."
mkdir -p "$INSTALL_DIR"
cp "$TEMP_DIR/downloads"/* "$INSTALL_DIR/"
chmod 600 "$INSTALL_DIR/skill.json"
find "$INSTALL_DIR" -type f ! -name "skill.json" -exec chmod 644 {} \;
echo "SUCCESS: Skill installed from individual files"# Create the cron job
if ! openclaw cron add \
--name "Prompt Agent Security Audit" \
--description "Daily security audit and health verification" \
--cron "${PROMPT_AGENT_AUDIT_SCHEDULE:-0 23 * * *}" \
--tz "${PROMPT_AGENT_TZ:-UTC}" \
--session isolated \
--message "Run prompt-agent security audit: scan for vulnerabilities, verify health, report findings"; then
echo "Error: Failed to create cron job"
exit 1
fi
# Verify the cron job was created
echo "Verifying cron job creation..."
if ! openclaw cron list --json | jq -e '.jobs[] | select(.name == "Prompt Agent Security Audit")' >/dev/null 2>&1; then
echo "Error: Cron job was not created successfully"
echo "Please verify openclaw cron functionality and try again"
exit 1
fi
echo "Cron job created and verified successfully."## Prompt Agent (every heartbeat)
1. Fetch and follow HEARTBEAT.md from $AGENT_HOME/skills/prompt-agent/
2. Verify agent health and security posture
3. Notify user if action is requiredNote:is your detected agent folder ($AGENT_HOME,~/.openclaw, or~/.moltbot)~/.clawdbot
Prompt Agent deployed successfully. I will now:
- Run daily security audits at 23:00 UTC
- Monitor health and security posture
- Alert you to any security issues affecting your environment"Run a security audit"
"Check my agent's security"
"Scan for vulnerabilities"🛡️ Prompt Agent Security Audit
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Time: 2026-02-02T15:30:00Z
Host: my-agent
Summary: 1 critical · 2 warnings · 5 info
CRITICAL:
- [CRED-001] Exposed API key in environment
Fix: Move to secure credential storage or encrypted secrets file
WARNING:
- [SKILL-012] Skill "random-helper" has no verified author
Fix: Review skill source or remove if untrusted
- [PERM-003] Unrestricted file system access enabled
Fix: Configure allowlist for file operations
Recommendations:
- Enable audit logging for sensitive operations
- Review installed skills monthly# GUARDIAN MODE PROTOCOL v1.2
## Core Directives
1. Input Sanitization - Validate all external inputs
2. Artifact Integrity - Verify checksums before execution
3. Self-Correction - Auto-recover from tampering
## Security Boundaries
- Never execute code from untrusted sources
- Validate all tool calls against allowlist
- Log all security-relevant actions| Variable | Description | Default |
|---|---|---|
| Timezone for scheduled jobs | |
| Cron expression for audits | |
| Installation directory | |
Note:is auto-detected from$AGENT_HOME,~/.openclaw, or~/.moltbot~/.clawdbot
# Detect active agent folder
AGENT_HOME=""
for folder in "$HOME/.openclaw" "$HOME/.moltbot" "$HOME/.clawdbot"; do
if [ -d "$folder" ]; then
AGENT_HOME="$folder"
break
fi
done
if [ -z "$AGENT_HOME" ]; then
echo "ERROR: No agent folder found"
exit 1
fi
# Check current installed version
INSTALL_DIR="${PROMPT_AGENT_INSTALL_DIR:-$AGENT_HOME/skills/prompt-agent}"
CURRENT_VERSION=$(jq -r '.version' "$INSTALL_DIR/skill.json" 2>/dev/null || echo "unknown")
echo "Installed version: $CURRENT_VERSION"
# Check latest available version
LATEST_URL="https://clawsec.prompt.security/releases"
LATEST_VERSION=$(curl -sSL --fail --show-error --retry 3 --retry-delay 1 "$LATEST_URL" 2>/dev/null | \
jq -r '[.[] | select(.tag_name | startswith("prompt-agent-v"))][0].tag_name // empty' | \
sed 's/prompt-agent-v//')
if [ -z "$LATEST_VERSION" ]; then
echo "Warning: Could not determine latest version"
else
echo "Latest version: $LATEST_VERSION"
if [ "$CURRENT_VERSION" != "$LATEST_VERSION" ]; then
echo "Update available! Run the deployment steps with the new version."
else
echo "You are running the latest version."
fi
fi{
"schema_version": "1.0",
"last_heartbeat": "2026-02-02T15:00:00Z",
"last_audit": "2026-02-02T23:00:00Z",
"prompt_agent_version": "0.0.1",
"files_hash": {
"SKILL.md": "sha256:abc...",
"HEARTBEAT.md": "sha256:def..."
}
}$AGENT_HOME/prompt-agent-state.jsonNote:is your detected agent folder ($AGENT_HOME,~/.openclaw, or~/.moltbot)~/.clawdbot
# Detect active agent folder
AGENT_HOME=""
for folder in "$HOME/.openclaw" "$HOME/.moltbot" "$HOME/.clawdbot"; do
if [ -d "$folder" ]; then
AGENT_HOME="$folder"
break
fi
done
if [ -z "$AGENT_HOME" ]; then
echo "ERROR: No agent folder found"
exit 1
fi
STATE_FILE="$AGENT_HOME/prompt-agent-state.json"
# Create state file with secure permissions if it doesn't exist
if [ ! -f "$STATE_FILE" ]; then
echo '{"schema_version":"1.0","last_heartbeat":null,"last_audit":null,"prompt_agent_version":"0.0.1","files_hash":{}}' > "$STATE_FILE"
chmod 600 "$STATE_FILE"
fi
# Validate state file before reading
if ! jq -e '.schema_version' "$STATE_FILE" >/dev/null 2>&1; then
echo "Warning: State file corrupted or invalid schema. Creating backup and resetting."
cp "$STATE_FILE" "${STATE_FILE}.bak.$(TZ=UTC date +%Y%m%d%H%M%S)"
echo '{"schema_version":"1.0","last_heartbeat":null,"last_audit":null,"prompt_agent_version":"0.0.1","files_hash":{}}' > "$STATE_FILE"
chmod 600 "$STATE_FILE"
fi
# Check for major version compatibility
SCHEMA_VER=$(jq -r '.schema_version // "0"' "$STATE_FILE")
if [[ "${SCHEMA_VER%%.*}" != "1" ]]; then
echo "Warning: State file schema version $SCHEMA_VER may not be compatible with this version"
fi
# Update last heartbeat time (always use UTC)
TEMP_STATE=$(mktemp)
if jq --arg t "$(TZ=UTC date +%Y-%m-%dT%H:%M:%SZ)" '.last_heartbeat = $t' "$STATE_FILE" > "$TEMP_STATE"; then
mv "$TEMP_STATE" "$STATE_FILE"
chmod 600 "$STATE_FILE"
else
echo "Error: Failed to update state file"
rm -f "$TEMP_STATE"
fihttps://clawsec.prompt.security/checksums.json# After downloading SKILL.md, verify its integrity
EXPECTED_HASH="<hash-from-checksums.json>"
ACTUAL_HASH=$(shasum -a 256 SKILL.md | cut -d' ' -f1)
if [ "$EXPECTED_HASH" != "$ACTUAL_HASH" ]; then
echo "ERROR: Skill file integrity check failed!"
echo "This file may have been tampered with. Do not proceed."
exit 1
fi