Skip to content

Instantly share code, notes, and snippets.

@gornostay25
Last active August 31, 2021 20:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gornostay25/3ea24d743c90b2cd6b2aaadb9241fec9 to your computer and use it in GitHub Desktop.
Save gornostay25/3ea24d743c90b2cd6b2aaadb9241fec9 to your computer and use it in GitHub Desktop.
Run jscode from string in sandbox
function sandboxcode(s) {
function construct(c, a) {
function F(){return c.apply(this, a)}
F.prototype = c.prototype;
return new F()
}
let g = ["Function","globalThis","eval"]
for (let i in globalThis){g.push(i)}
g.push(s);
return construct(Function, g).apply({});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment