Well, that raises a more complex issue of exactly what we mean by code 'running in IPython'. But if that's a common case, one obvious approach would be to set a builtin, or some other globally accessible variable, all the time that IPython is running.

Alternatively, we could provide a function to copy&paste that checks whether IPython is in `sys.modules`, and only calls `IPython.get_ipython()` if it is.