An Albanian man told a judge he just wants to return home - and he was given a map showing him where the nearest police station was.
Rumnici Marjus is an illegal immigrant and said he wanted to go to a police station so he can be detained and returned to Albania.
Exeter Crown Court heard he had been on remand in jail since the end of February after being caught with cocaine.
His lawyer Kelly Scrivener said: "He is homeless and has not claimed asylum.
He lives hand to mouth and he wants to go home."
The 32 year old was jailed for a month after admitting possessing cocaine and was freed immediately.
Judge Stephen Climie said: "I have no control over the immigration authorities. I don't know what the future holds for you."
The judge said Marjus would be given a map to show him where Exeter's main police station was so he could hand himself in as an illegal immigrant.
Elsewhere, a Pakistani paedophile labelled a "danger to the community" escaped deportation because he is an alcoholic, a shocking ruling has revealed.
The sex offender, who was jailed for sexually assaulting a girl under 13, was allowed to remain because of his "uncontrollable alcohol consumption".
An asylum tribunal also heard the man, who was granted anonymity, is considered a "danger to the community" and has also been convicted in Britain of another sexual assault, beating his wife, and assaulting emergency workers.
But the tribunal ruled the predator could be jailed because alcohol is illegal in Pakistan.
This, the judge ruled, would violate his human rights.