When a script is running within a session, it can clean up that session by calling the command:
CleanupSession;
When this command completes, the data for the session has been removed from disk, and the constant _sessiondir is empty. Also, the value of _session_active will be set to False, and _sessionid will be empty.
In addition to this per-session cleanup command, the command ExpireSessions can be used to clean up old sessions in bulk, based on age (time since session creation) or the elapsed time since the last time the session was accessed.