Install
openclaw skills install file-manager-securePerform safe file operations with path validation, dry-run previews, recoverable trash deletes, batch confirmations, and audit logging to prevent data loss.
openclaw skills install file-manager-securename: file-manager-secure description: Safe file operations with validation, dry-run mode, and trash recovery. Alternative to dangerous rm/mv/cp commands.
Secure file management with data loss prevention:
def validate_path(path: str) -> Path:
# Resolve to absolute
full_path = Path(path).resolve()
# Check forbidden patterns
FORBIDDEN_PATTERNS = [
r"\.\.", # Parent directory traversal
r"~/.ssh",
r"~/.gnupg",
r"~/.aws",
r"~/.docker",
r"~/.kube",
r"\.env",
r"secret",
r"token",
r"credential",
r"/etc/passwd",
r"/etc/shadow",
r"C:\\Windows\\System32",
r"REGISTRY\\",
]
# Must be within workspace or explicit allowlist
WORKSPACE = Path.home() / ".openclaw" / "workspace"
ALLOWED_DIRS = [WORKSPACE, Path.home() / "Downloads", Path.home() / "Documents"]
for allowed in ALLOWED_DIRS:
try:
full_path.relative_to(allowed)
return full_path
except ValueError:
continue
raise PermissionError(f"Path {path} is outside allowed directories")
@dataclass
class FileOperation:
op: str # 'copy', 'move', 'delete', 'rename'
source: Path
dest: Optional[Path]
size: int
confirm_required: bool
# All operations return preview first
operations = plan_operations(files, action='delete')
show_preview(operations) # User reviews
execute_with_confirmation(operations) # Only after OK
TRASH_DIR = WORKSPACE / ".trash"
def safe_delete(path: Path):
# Move to trash with metadata
trash_entry = TRASH_DIR / f"{timestamp}_{path.name}"
metadata = {
"original_path": str(path),
"deleted_at": timestamp,
"size": path.stat().st_size,
}
shutil.move(path, trash_entry)
save_metadata(trash_entry, metadata)
# Auto-cleanup after 30 days
MAX_BULK_OPERATIONS = 50 # Require confirmation above this
MAX_TOTAL_SIZE = 100 * 1024 * 1024 # 100MB limit
# For large operations, require explicit --force flag
# Safe ls with filters
file-secure list /path/to/dir --type *.csv --sort size --reverse
# Content and name search
file-secure search "pattern" --in=/path --type=md --content # Search in content
file-secure search "dataset*" --in=/path --type=csv # Search by name
file-secure copy source.csv backup/ # Preview mode
file-secure copy source.csv backup/ --exec # Execute after preview
file-secure copy *.csv backup/ --exec # Bulk with confirmation
file-secure move old/ processed/ --exec
file-secure move *.tmp trash/ --exec # Safe to trash, recoverable
file-secure delete old.csv # Move to trash
file-secure delete *.log --older-than=30d # Delete old files
file-secure restore old.csv # Restore from trash
file-secure empty-trash # Permanent delete (with warning)
file-secure analyze datasets/ # Size by type, largest files
file-secure analyze datasets/ --duplicates # Find duplicates
file-secure backup important.csv
file-secure restore important.csv.bak
file_manager.py — Main operations with safety layerspath_validator.py — Path sanitizationtrash_manager.py — Trash operations and recoveryoperation_planner.py — Dry-run and batch planningsecurity_model.md — Complete security architecturerecovery_guide.md — How to restore deleted files