Working with your code, I'd try something like this:
\documentclass{article}
\usepackage{sagetex}
\lstdefinestyle{SageInput}{style=DefaultSageInput, numbers=none}
\begin{document}
\begin{sagecommandline}
sage: for i in range(0,4):
....: i^2
\end{sagecommandline}
\begin{sagesilent}
output = r""
for i in range(0,4):
output += r"\texttt{%s}\\"%(i^2)
\end{sagesilent}
\sagestr{output}
\end{document}
The output running in Cocalc is:

The code numbers=none turns off the line numbers, if that's something you wanted.
You might also be interested to know that my answer to the question Questions about including source code in a TeX file mentions that one of the developers of SAGE has posted a LaTeX file that he uses in typesetting SAGE.