How to safely maintain schools open during a pandemic is still controversial . We aim to identify those measures that effectively control the spread of SARS-CoV-2 in schools . By control we mean that each source case infects less than one other person on average . Here, we analyze Austrian data on 616 clusters involving 2,822 student-cases and 676 teacher-cases with the aim to calibrate an agent-based epidemiological model in terms of cluster size and transmission risk depending on age and clinical presentation . With this model, we quantify the impact of preventive measures such as room ventilation, reduction of class size, wearing of masks during lessons, and school entry testing by SARS-CoV2-antigen tests . We find that 40% of all clusters involved no more than two cases, and 3% of the clusters only had more than 20 cases . The younger the students, the more likely we found asymptomatic cases and teachers as the source case of the in-school transmissions . Different school types require different combinations of measures to achieve control of the infection spreading: In primary schools, it is necessary to combine at least two of the aforementioned measures . In secondary schools, where contact networks of students and teachers become increasingly large and dense, a combination of three measures is needed . A sensitivity analysis indicated that the cluster size might increase up to three-fold in secondary schools for virus variants with an increased transmissibility by 50%, and that poorly executed or enforced mitigation measures might increase the cluster size by a factor of more than 30 . Our results suggest that school-type-specific combinations of measures, when strictly adhered to, allow for a controlled opening of schools even under sustained community transmission of SARS-CoV-2 . However, large clusters might still occur on an infrequent, however, regular basis . It is shown explicitly that strict adherence to the measures is a necessary condition for successful control.