Updated

An Iranian-American sentenced to 18 years in Iran on accusations of "collaboration with a hostile government" has been freed from prison on bail, according to relatives and activists -- but instead of escaping from the Islamic Republic, he may be stuck there in a form of limbo.

Robin Shahini of San Diego got out recently on bail of about $62,000, according to Hadi Ghaemi, the executive director of the New York-based Center for Human Rights in Iran. He had staged a weeks-long hunger strike protesting his imprisonment alongside other dual nationals targeted by hard-liners -- and reportedly wrote a suicide note last year.

AMERICAN IMPRISONED IN IRAN PENS SUICIDE NOTE

For now, he may be at the mercy of an appeals court. Shahini would not be able to leave Iran until that court gives the OK, a close friend of his told The Foreign Desk.

"Shahini's release on bail is good news as his prosecution did not produce any credible evidence justifying charges against him," Ghaemi told The Associated Press. "He is an innocent man who appeared to be in the wrong place at the wrong time and his detention and prosecution was motivated by his dual nationality more than anything else."

AMERICAN JAILED IN IRAN ASKS FOR TRUMP’S HELP: ‘DO NOT LET ME BE ALONE’

Shahini, who traveled to Iran to see his mother who was diagnosed with Alzheimer's disease, was detained on July 11. He left Iran in 1998 and had lived in San Diego for 16 years. He graduated in May 2016 from San Diego State University with a degree in International Security and Conflict Resolution and had been accepted to SDSU's graduate program in Homeland Security.

At his trial, prosecutors apparently used social media pictures of Shahini standing near prominent Iranian exiles to secure his conviction. Hard-liners have been using such cases to challenge the administration of moderate President Hassan Rouhani ahead of the country's coming May presidential election. Rouhani is expected to run in the vote next month.

"I ask myself and my fellow American neighbors: Where is the justice I have come to associate with America?" Shahini wrote his family in a recent letter.

Iranian officials and state media did not comment on Shahini receiving bail. The Iranian mission to the United Nations and the U.S. State Department did not immediately comment.

Iran does not recognize dual nationalities, meaning that those it detains cannot receive consular assistance. In most cases, dual nationals have faced secret charges in closed-door hearings before Iran's Revolutionary Court, which handles cases involving alleged attempts to overthrow the government.

Analysts and family members of those detained have suggested that hard-liners in the Islamic Republic's security agencies want to negotiate another deal with the West to free the detainees. A prisoner exchange in January 2016 that freed Washington Post journalist Jason Rezaian and three other Iranian-Americans also saw the U.S. make a $400 million cash delivery to Iran the same day.

Among the dual national held are Iranian-American businessman Siamak Namazi and his octogenarian father, Baquer Namazi, who are serving 10-year prison sentences for "cooperating with the hostile American government." Another is Nazanin Zaghari-Ratcliffe, a British-Iranian woman sentenced to five years in prison on allegations of planning the "soft toppling" of Iran's government while traveling with her young daughter.

Yet to be tried is Iranian-American Karan Vafadari, an art gallery manager held along with his Iranian wife. Iranian-Canadian national Abdolrasoul Dorri Esfahani, a member of the country's team that negotiated the nuclear deal, is believed to have been indicted.

Still missing is former FBI agent Robert Levinson, who vanished in Iran in 2007 while on an unauthorized CIA mission.

Shahini began a hunger strike on Feb. 15 to contest his incarceration.

"My only sin was that as a responsible human being, I expressed my views about my homeland, which is the right of every citizen," he wrote in a letter to his family published by the Center for Human Rights in Iran. "Don't let me remain in this prison as an innocent man."

Fox News' Eric Shawn and The Associated Press contributed to this report.

Click for more from The Foreign Desk.