It was narrated that Anas bin Malik said: The Messenger of Allah (ﷺ) entered Al-Khala' (the toilet) and said: 'Allahumma inni a'uthu bika min al-khubuthi wal-khaba'ith (O Allah, I seek refuge with You from male and female devils). [1] [1] See Ma'alam As-Sunan by Al-Khattabi. And Al-Khala' is the area one relieves oneself in. It refers to outside or other than that, it should not be understood to mean toilet only.
انس بن مالک رضی اللہ عنہ کہتے ہیں کہ رسول اللہ صلی اللہ علیہ وسلم جب پاخانہ کی جگہ میں داخل ہوتے تو یہ دعا پڑھتے: «اللہم إني أعوذ بك من الخبث والخبائث» اے اللہ! میں ناپاک جنوں اور جنیوں ( کے شر ) سے تیری پناہ چاہتا ہوں ۔