London — FOR most of the years that I was based in Iran as a correspondent for Time magazine, my working life approximated a clumsy script for a television spy drama. I was regularly obliged to meet with intelligence agents who monitored my writing and hectored me to disclose the identities of sources. These interrogation sessions usually took place in empty apartments across Tehran, places where no one could have heard me scream, and always with stern warnings that nobody could know they were taking place.

I got used to seeing an unidentified number flashing on my cellphone, picking up a call from a voice that would not identify itself. I got used to my assigned agent’s macabre jokes, to being followed and sometimes threatened. As he revealed things about my life only those close to me would know, I grew to distrust many of my friends, and felt tainted by his role in my life. But for me, working in Iran involved such an association.

As a child of Iranian exiles living in California, I grew up hearing that the Islamic Republic was merciless. So when I first traveled back to Iran — where I held dual citizenship — to work in 1999, I expected some level of scrutiny. At first, watching the Western reporters around me operating relatively freely, I imagined the challenges would be tolerable.

Only at the very end of my time there did I realize I had been in the hands of the “good guys.” Since I left in 2007, the Islamic Republic’s intelligence apparatus has grown steadily, in tandem with the political establishment’s own increasing fragmentation. Factions within the judiciary and the Revolutionary Guards who often work at cross-purposes with the government have developed their own intelligence bodies that operate with impunity, a deep state that is determined to sabotage détente with the United States and to undermine the pragmatic forces that signed July’s nuclear deal to end Iran’s isolation.