tos library / API / tos.is_root
tos.is_root()
Returns True when the host shell has activated root mode, otherwise False. Detection is done by reading the TOS_ROOT_ACTIVE environment variable and comparing it to the literal string "TRUE".
Synopsis
tos.is_root() -> bool
Behaviour
def is_root():
return os.getenv("TOS_ROOT_ACTIVE") == "TRUE"
- The check is case sensitive:
"true"returnsFalse. - If
TOS_ROOT_ACTIVEis unset,os.getenvreturnsNoneand the function returnsFalse.
Example
import tos
def wipe_disk():
if not tos.is_root():
print("Refusing to wipe disk — not in root mode.")
return
print("Wiping...")
wipe_disk()
Note: The TrashOS shell sets this variable when the user issues the root command and successfully authenticates. See TrashOS Reborn for details.