The head of the United Nations refugee agency on Sunday urged Libyan authorities to free all asylum seekers and refugees from its detention centres as he visited Tripoli.
"I hope first of all that asylum seekers and refugees can be taken out of detention centres," UN High Commissioner for Refugees Filippo Grandi said after visiting one centre in the Libyan capital.
"I fully appreciate that the government has security concerns," he said, but added that "other solutions" could be found for people fleeing countries in conflict such as Syria and Somalia.
Thousands of migrants are being held in dozens of detention centres in Libya, after being stopped or rescued from rickety boats as they attempted the perilous Mediterranean crossing to Europe.
"I was shocked at the harsh conditions in which refugees and migrants are held," Grandi said in a statement released on Sunday by the agency's Geneva headquarters.
"Children, women and men who have suffered so much already should not have to endure such hardship."
The UN refugee agency has secured the release of more than 800 refugees and asylum seekers from Libyan detention centres over the past year and a half, the statement said.
Grandi promised to reinforce his agency's presence in Libya if security conditions allowed it, and also to provide assistance to thousands of Libyans displaced by conflict.
Libya descended into chaos after the 2011 uprising that killed and toppled Moamer Kadhafi, with rival authorities and militias vying for control of the oil-rich country.