Search code examples
phpscopesandbox

Is it possible to run PHP code in isolation?


Is it possible to run user submitted PHP code in an isolated scope? Meaning the code would not have access to any outer resources on the machine or php environment?

Or is the only option to go with javascript and execute it in a V8js object?

I find no good articles on the web. :(


Solution

  • The Sandbox in the Runkit PECL extension (not embedded with PHP) seems to be able to do this. http://docs.php.net/runkit

    $sandbox = new Runkit_Sandbox($options);
    $sandbox->ini_set(…);
    $sandbox->eval($code);
    

    https://github.com/zenovich/runkit https://github.com/runkit7/runkit7