It depends on what you mean by "Sage is running". If you mean, "have the standard Sage commands, etc., been imported and are ready for use," then you could test
import sys
if 'sage' in sys.modules:
print('The Sage library has been imported')
This seems to be the case with the Sage Cell server for both Sage and Python: Sage has been imported in both cases. That's why your test isn't distinguishing the two. Along the same lines, print(sage.version.version)
returns 10.2 in both Sage and Python on the Sage Cell server.
If you mean, "is Sage's preparser running," then the answer from @PedroBrazil is correct. In Python, ^
means bitwise exclusive or, while by default in Sage, ^
is exponentiation. The preparser can be turned off while still running Sage, though, so this is not a perfect test.
My guess is that the "Python" setting for the Sage Cell Server imports all of Sage and just turns off the preparser. So again, it depends on what you need to test, why you need to know whether it's Sage or Python.