Rescuers are racing to pull dozens of students and workers from under the rubble of a school building that collapsed in East Java, Indonesia.

Three people have been killed and 99 others hospitalised, some of them with critical injuries, officials said Tuesday, adding that the death toll may rise.

At least 38 others, many of them teenage boys, remain trapped under the Al Khoziny Islamic Boarding School in the East Java town of Sidoarjo. They had gathered for prayers when the building gave way on Monday.

The two-storey building had an unstable foundation and could not support the weight of the construction of two more floors, the disaster mitigation agency said.

The girls were praying in another part of the building and managed to escape, according to the Associated Press.

Footage on local media shows the collapsed part of the building completely sunken in, with large slabs of concrete sticking out.

Crying and shouting can be heard from the rubble, authorities said, while anxious relatives have camped out at the school overnight awaiting news of their loved ones.

Dozens of rescuers have been searching overnight for survivors, but the rescue was temporarily suspended on Tuesday, with authorities saying the building is at risk of further collapse.

The building's collapse has assumed a pancake-like structure with layers of concrete slabs, leaving only narrow voids which complicates rescue efforts, said Mohammad Syafeii, head of the search and rescue agency Basarnas.

The agency is preparing for a specialised operation and has deployed units from around the region equipped with special extrication tools.

The school's caretaker, KH Abdus Salam Mujib, apologized to students' families, attributing the incident to God's will and hoped for something better to come from this tragedy.

Despite the oversight by Indonesia's Ministry of Religious Affairs, this incident shines a light on the lack of regulatory enforcement in the construction sector, where incidents like these have become alarmingly common.