Tonoi was to guard the Imperial Palace, Kanshi (government officials) and the nobility under the ancient Ritsuryo Code (criminal and civil laws).
Originally under the Shikisei-ritsu (Office Penal Laws) (Zaikan Ochoku Fuchoku no jo (在官応直不直条, the article of guarding activities)) the guarding activity during the day was expressed as '宿' and the night activity as '直' and the combination of '宿直' was read as 'Tonoi,' but later it only came to mean the guarding activity during the night, which was described '宿直' or '殿居' and both were read as 'Tonoi.'
According to Kushiki-ryo (law on state documentary forms in the Yoro Code) (Hyakkan-tonoi no jo (百官宿直条, the article of Tonoi for all the officials)) all the Kanshi (government officials) except Dainagon (chief councilor of state) or higher officials and ministers of Hassho (eight ministries and agencies) were supposed to assume the obligation of Tonoi in alternate shifts for the section to which they belonged. The time table for Tonoi was made by jo (inspector (third highest of the four administrative ranks of the ritsuryo period) of each section (which were corresponding Shonagon (lesser councilor of state) and Benkan (officials of the dajokan) in Daijokan (Grand Council of State), Taijo (Senior Secretary) and Shojo (Junior Secretary) in Hassho (eight ministries and agencies), and jo (provincial governor) in local governments) and was submitted to Benkan every day.
Besides above, as a part of their duties, Hyoe (palace guard) and udoneri (Ministerial equerry) guarded the Imperial Palace, and Otoneri (Royal Attendant), Togu Toneri (Officer of the Crown Prince's palace) and Chugu Toneri (Officer of the Household of the Empress) guarded the Emperor, Togu (Crown Prince's Palace) and Chugu (Empress's Palace) respectively in alternate shifts.
During the Heian period, Konoe-fu (the agency to guard the Palace) guarded at night the Imperial Palace and Okura (financial department) and Uchikura (Inner Treasury)
According to "Engishiki " (codes and procedures on national rites and prayers), Sakonefu (Left Division of Inner Palace Guards) took the duty from I-no-koku to Ne-no-koku (from nine o'clock in the evening to one in the morning), and Ukonefu (Right Division of Inner Palace Guards) did from Ushi-no-koku to Tora-no-koku (from one o'clock to five in the morning). Kanjin (government officials) in Konoe-fu patrolled crying out their own names, and this was called Tonoi-moshi. In spite of the provisions of the Ritsuryo Code, ministers and Dainagon, along with Chunagon, Kurodo no to (Head Chamberlain) and Konoe no daisho (Major Captain of the Palace Guards), stayed at Tonoidokoro (Tonoi's station) and Jikiro (ministers and counselors' station for attendance) in the Imperial Palace during the night in order to prepare for an emergency.