Detecting Sandboxed Standard Libraries
Sandboxes frequently strip or stub out standard library functions to limit what obfuscated scripts can do. Probing for the presence and behavior of these functions reveals whether your code is running in a restricted environment.Library Presence Checks
Check whether functions that are normally available in a full Lua VM are missing or non-functional:os.exit and io are particularly common targets for removal because they allow scripts to affect the host system.
Scoring Function
Convert the results into a suspicion score that you can threshold against:Detecting Behavioral Anomalies
Even when libraries are present, sandboxes and emulators often behave differently from a real Lua VM. Detect these anomalies by probing deterministic behavior.math.random Seed Anomalies
In a real Lua VM,math.random without an explicit seed uses a default seed derived from the system time. In some sandboxes, the RNG is seeded to a fixed value for reproducibility. Check whether the sequence matches an expected non-seeded pattern:
Time Anomalies
Sandboxes sometimes return a fixed or stepped time fromos.time(). Check whether time advances between two calls separated by a busy-wait loop:
os.time() does not advance, the environment may be emulated or time is being controlled.
Function Address Anomalies
In a real Lua VM,tostring of a function includes a process-specific address. In some emulated VMs, function addresses are always 0x0 or a fixed value:
0x0 address suggests the VM is not allocating real function objects.
Coroutine Behavior Checks
Some sandboxes implement coroutines incorrectly. A specific yield and resume pattern may produce wrong status values or fail to preserve values across yields.Coroutine Canary Test
Metatable Behavior Checks
Metamethods are complex to emulate correctly. A sandbox with a simplified object model may fail to invoke__index and __newindex under all circumstances.
Metatable Canary Test
index_called or newindex_called is false, the sandbox does not implement metamethods faithfully.
Detecting Known Deobfuscators
Some deobfuscators leave fingerprints in the global environment or modify standard functions in recognizable ways.Global Name Fingerprints
Check for global names that deobfuscators inject to mark or hook your code:pcall Wrapper Detection
Deobfuscators often wrap your script inpcall to catch errors during analysis. You can detect this by raising an error and inspecting the stack depth:
