Indonesia has released some 18,000 inmates in a desperate bid to stop coronavirus from rampaging through its notoriously overcrowded prison system, authorities said Thursday.

The mass release comes days after the Southeast Asian nation said it would free more than 30,000 inmates to take pressure off prisons and jails beset by unsanitary conditions and long at risk of infectious diseases.

The UN has called on countries to release vulnerable inmates, with Afghanistan last week announcing it would set free some 10,000 prisoners.

"Our target is to release 30,000 inmates in total, but it could end up being more," said Rika Aprianti, a spokeswoman for the Corrections Directorate General.

"This is part of the plan to prevent the spread of COVID-19 in prisons."

She offered few details, but a government release order included juvenile offenders and adult prisoners who had served at least two-thirds of their sentences.

Prisoners were advised to self quarantine at home after release.

Among them was Firdaus, a fishermen jailed in 2017 on Sulawesi island for stealing a gold ring.

"I was scared of being infected in prison, not to mention that the guards come and go so we don't know who they've had contact with," said the 33-year-old, who was set for release in November.

But his relief was tempered by the thought of others still inside.

"I'm not that happy because I left my friends behind," he said.

Indonesia's creaking prison system has just 522 institutions for some 270,000 inmates. It suffers from regular jailbreaks and criticism for its often deplorable conditions.

Amnesty International welcomed the release, but called on the government to make sure "prisoners of conscience" and older inmates with health problems were set free.

"They're vulnerable to COVID-19 and, in the name of humanity, they must be released," said Amnesty Indonesia Executive Director Usman Hamid.

"Conditions including a lack of access to clean water and severe overcrowding will be exacerbated by the outbreak."