Tweak sandbox code to make it more reliable