I think you need a try/catch here to handle the infinite loop case (like Turtle.execute).

Also, do you want to store this in Turtle.code or just a local variable instead?  I'm worried about side effects since previously Turtle.code only contained the user's code after they clicked the Run button.