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. Students in the school are between the ages of 12 and 17.

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 collapsed building has taken on a pancake type structure with layers of concrete slabs leaving only narrow voids, unstable conditions, and the possibility of survivors still trapped, said Mohammad Syafeii, head of the search and rescue agency Basarnas.

His agency is preparing for a specialised operation and has deployed units from around the region that will be equipped with special extrication tools, he said.

Mr Syafeii also laid out the dilemma with the use of heavy equipment, such as cranes and excavators. While they help lift the concrete slabs and open access, shifting the slabs may also endanger the lives of survivors still trapped beneath the rubble, he said.

Rosida, whose son Kaffa Ahmad Maulana is among those missing, said she has been waiting for news since Monday evening. Another of her children, who was also affected by the collapse, is being treated at a hospital.

Students who survived the incident have recounted their harrowing escapes. Seventh grader Muhammad Rijalul Qoib said hundreds of people had gathered to pray when they heard the sound of falling rocks.

It got louder and louder, the 13-year-old told reporters.

Another student, Sofa, said he saw classmates with lots of injuries and broken bones.

Al Khoziny is a traditional Islamic boarding school, or pesantren, known for its focus on Islamic studies, yet many now offer general education. The school's management has been criticized for not obtaining permits for the building expansion, which Sidoarjo town's regent confirmed.

Indonesia's construction industry has been noted for its poor safety record, making incidents like this alarmingly common.