You might be able to do this with a web-based Python shell like Jupyter.
However I'd like to suggest an alternative approach. Rather than figure
out a way for the user to have this same kind of shell interaction on the
web, what about integrating Django with the underlying protocol, SAML?