There is always a stack limit, which always prevents infinite recursion; as well as, in fact, finite but very deep recursion.
As Ben said, the only way to prevent infinite or long-running loops is by interrupting the program from another thread. You may have heard of the Halting Problem, TL;DR: there really can be no other way, because in the general case it is impossible to predict whether a loop will terminate at all, and how soon.
There is no way to set a limit for executed instructions. You could hack it, but it's going to be non-trivial.