JSFiddle - React, Tailwind, and code Playground
HTML
<script id="sandbox" type="text/sandbox">
debugger;
var func = new ({}).constructor.constructor('', 'this.alert(123);');
func();
(1,eval)('alert(123)');
</script>
JavaScript
var code = document.getElementById('sandbox').textContent;
sandbox(code);
function sandbox(__code) {
var __vars = ['__vars', '__global', '__script'], __global = this, __script;
while(__global) {
__vars = __vars.concat(Object.getOwnPropertyNames(__global));
__global = Object.getPrototypeOf(__global);
}
__vars = __vars.reduce(function(array, key) {
if(!key.match(/^\d/) && !key.match(/,/) && key.match(/^[\w\d]+$/) && array.indexOf(key) === -1)
array.push(key);
return array;
}, []);
new Function('', code);
Function.prototype.constructor = function fakeConstructor() {};
__script = document.createElement('script');
__script.type = 'text/javascript';
__script.text = '(function() {\n' +
' var ' + __vars.join(', ') + ';\n' +
' (function() {\n' +
' "use strict";\n' +
code + '\n' +
' })();\n' +
'})();\n';
document.head.appendChild(__script);
}