Python Hardener for Openclaw

Openclaw Skills Python Hardener transforms one or more Python scripts into secure, production-ready versions with better errors, logging, docs, and safer I/O.

kikikari
v0.1.0
Jul 15, 2026
0
326
0

Install & Download

1. ClawHub CLI

The fastest way to install a skill directly from the registry.

npx clawhub@latest install skill-python-hardener

2. Manual Installation

Copy the skill folder to one of these locations

Global
~/.openclaw/skills/
Workspace
<project>/skills/

Priority: Workspace > Local > Bundled

3. Prompt Installation

Copy this prompt to OpenClaw to install it automatically.

Help me install skill-python-hardener using Clawhub. If Clawhub is not installed, install it first (npm i -g clawhub).

Prefer to download?

Get the raw skill files in a ZIP archive.

What is Python Hardener?

Python Hardener is an Openclaw Skills workflow for taking uploaded or referenced Python files and rewriting them in place with safer control flow, cleaner structure, and production-grade observability.

It performs a full review for injection risks, weak exception handling, resource leaks, unsafe path and subprocess usage, non-atomic writes, and missing documentation, then produces a companion Markdown file that explains the security measures applied and how each module works.

Python Hardener Use Cases

  • Review Python scripts for SQL/NoSQL injection, shell injection, path traversal, or hardcoded secrets.
  • Replace bare except: blocks and silent pass statements with specific exceptions and explicit logging.
  • Convert print-driven scripts to centralized logging with RotatingFileHandler and a console StreamHandler.
  • Refactor messy code into clearer functions, better variable names, and type-hinted interfaces.
  • Harden multiple uploaded .py files in one pass while preserving the original filenames exactly.
  • Produce a single companion Markdown document for auditability, onboarding, or handoff.
  • Make one-off utilities production-ready without inventing new project scaffolding or migration files.

How Python Hardener Works

  1. Read all provided Python files end to end and build a mental inventory of issues across security, error handling, performance, resource management, and clean code.
  2. Identify unsafe patterns such as interpolated SQL, shell=True, os.chdir(), path traversal, hardcoded secrets, and broad exception handlers, then choose safer replacements.
  3. Rewrite the same files in place, preserving the original filenames and overall structure unless a name or pattern is actively harmful.
  4. Apply production logging once via a dedicated setup function, using RotatingFileHandler for file output, StreamHandler for console output, and an environment-driven log level.
  5. Add Google-style docstrings and type hints to public functions, methods, and classes, including Args, Returns, and Raises coverage.
  6. Generate one companion Markdown document named <primary-script-name>.md that documents the architecture, configuration, APIs, security fixes, and error handling behavior.
  7. Verify the final output against the checklist: no bare except:, no os.chdir(), closed resources, atomic writes, and no extra files beyond the approved documentation artifact.

Python Hardener Setup

  1. Provide the target .py file or files and request hardening; no separate install step is required for Openclaw Skills.
  2. If the script already relies on runtime configuration, set the environment variables before executing the hardened output.
export LOG_LEVEL=INFO
  1. Run the rewritten files from their original locations; filenames remain unchanged.
  2. Review the generated <primary-script-name>.md companion document for the applied fixes and module behavior.

Do not expect the skill to create .env.example, requirements.txt, or migration guides unless you explicitly ask for them.

Python Hardener Data Schema & Taxonomy

Artifact Structure Purpose
Input scripts One or more .py files supplied by the user Source code to analyze and harden
Patched scripts The same filenames as the input files Corrected code written in place
Companion documentation <primary-script-name>.md Single Markdown report for the primary script
Runtime configuration Environment variables consumed by the script Replaces hardcoded secrets and controls log level
Metadata bucket Typical contents Notes
Security SQL/NoSQL injection, shell injection, path traversal, secrets Each threat maps to an explicit countermeasure
Error handling Specific exceptions, warnings, error logs, fallback behavior Bare except: and silent pass are removed
Resource management Context managers, connection closure, atomic writes Prevents leaks and torn writes
Code quality Type hints, naming, function decomposition, docstrings Preserves intent while improving readability
Documentation Overview, architecture, configuration, API/functions, security, error handling Captures the final state for review

The skill does not generate extra scaffolding files or a persistent schema beyond the rewritten source and the single Markdown artifact.

Python Hardener Advanced Features

  • Multi-file hardening support: when multiple Python files are uploaded together, each file is reviewed and fixed.
  • Allowlist-driven defenses for risky inputs, including table names, paths, and other user-controlled values.
  • Safer subprocess handling with list-form commands and no shell=True.
  • Resource-leak remediation using context managers for files, database connections, and network handles.
  • Atomic file writes with temporary files plus os.replace() to prevent torn state updates.
  • Logging modernization that reads log level from the environment and standardizes file and console output.
  • Documentation generation that captures architecture, security posture, API surface, and error behavior in a single companion file.
  • Preserves the original filenames and avoids unnecessary project scaffolding, making it ideal for Openclaw Skills review-and-fix workflows.

SKILL.md


Loading

Related Openclaw Skills

METADATA

Github Stars: 0
forks: 0

Featured*