Refactor sandbox running code