run-python-safely

Execute Python code securely using AST-based analysis and enforced timeouts.

Updated Nov 11, 2025
One-click install
npx skills add https://github.com/libertininick/chain-reaction --skill run-python-safely
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: run-python-safely
Source: https://github.com/libertininick/chain-reaction/tree/main/.claude/skills/run-python-safely
Command: npx skills add https://github.com/libertininick/chain-reaction --skill run-python-safely

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) components.

What problem does it solve?

Automates safe execution of Python code generated by agents.

Core Features & Use Cases

  • AST-based analysis to detect and block dangerous operations before execution.
  • Supports running code inline or from files to fit into automated workflows.
  • Enforces a 5-minute timeout and exposes clear exit codes for blocked or timed-out runs.
  • Ideal for agent workflows and testing pipelines where Python code is dynamically produced.

Quick Start

Inline code: uv run python .claude/skills/run-python-safely/scripts/run_python_safely.py -c "print(2 + 2)" File-based: uv run python .claude/skills/run-python-safely/scripts/run_python_safely.py -f script.py

Frequently Asked Questions about run-python-safely

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I safely execute agent-generated Python code?

To safely execute agent-generated Python code, this skill applies AST-based analysis to block dangerous imports, builtins, and filesystem-modifying methods before running inline code or scripts.

Can I run Python files from automated agent workflows without security risks?

Yes, you can run Python files from automated agent workflows by passing the file path to the execution script, which analyzes the AST and blocks dangerous operations prior to execution.

What is AST-based analysis for blocking dangerous Python operations?

AST-based analysis parses Python code into an abstract syntax tree to detect and prevent dangerous imports, builtins, and filesystem-modifying methods from executing in automated pipelines.

How do I set up a timeout for executing dynamically generated Python scripts?

To set up a timeout for dynamically generated Python scripts, this skill enforces a strict 5-minute execution limit and returns standardized exit codes for timed-out or blocked runs.

Does this Python execution skill work with inline code strings?

Yes, this Python execution skill works with inline code strings by accepting a command-line argument, allowing you to quickly test and execute dynamically generated snippets safely.

What are the limitations of using AST analysis for Python code safety?

A limitation of using AST analysis for Python code safety is that it specifically blocks dangerous imports, builtins, and filesystem-modifying methods, while enforcing a 5-minute timeout to prevent runaway processes.