Thousands of migrants are being held in dozens of detention centres in Libya, after being stopped or rescued from rickety boats.
"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.
"The time has come for us, as the UN refugee agency, to step up our presence and activities in the country," Grandi later told AFP.
He said that doing so could take time for political and security reasons, however.
"But meanwhile we are doing whatever we can to help the Libyans manage better these issues," he said.
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.