They can become hairdressers at salons, dancers in risqué shows, occasionally even pop stars. Many, though, work the streets, begging during the day and engaging in prostitution or other sex work at night.

“I’ve always been devout,” said Edo, a 39-year-old sex worker who uses only one name, as she sat on the school’s front steps, adjusting her green hijab, which she wore with a conservative black gown. After going out on Saturday evenings to meet clients, she will often head to the school for Sunday worship.

“There’s no contradiction,” she said, crediting this realization to her study at the pesantren, the Indonesian word for madrasa. Like other women here, she goes by a name she chose for herself after transitioning genders.

Such a student body has its challenges. Transgender women often live in poverty with unstable family lives.

The school’s 40 or so students tend to be older than those at a traditional madrasa, who are usually in their teens or early 20s. Some are as young as their late teens, but mostly they are middle-aged and have missed traditional Islamic education because they were expelled from home as teenagers.

“Many students come and go,” Ms. Shinta said.

She wants to bring waria from the edges into the center of Indonesian life. And in this increasingly religious country, that means bringing them into the center of Islam.