refactor sandbox to allow plugins to register global functions

plugins may change Sandbox.env