In espionage, a resident spy is an agent operating within a foreign country for extended periods of time. A base of operations within a foreign country with which a resident spy may liaise is known as a "station" in English and a rezidentura (residency) in Russian parlance. What the U.S. would call a "station chief", the head spy, is known as a rezident in Russian.
Types of resident spies
In the former Soviet Union and Russian nomenclature, there are two types of resident spies: legal'nye rezidenty (легальные резиденты, legal resident spy) and nelegal'nye rezidenty (нелегальные резиденты, illegal resident spy). In US parlance, the same distinction is between "official cover" and "non-official cover".
A legal resident spy operates in a foreign country under official cover (such as from his country's embassy). He is an official member of the consular staff, such as a commercial, cultural, or military attaché. Thus, he has diplomatic immunity from prosecution and cannot be arrested by the host country if suspected of espionage. The most the host country can do is send him back to his home country as persona non grata.
An illegal resident spy operates under non-official cover and so he cannot claim immunity from prosecution when arrested. He may operate under a false name and has documents making him out to be an actual national or from a different country from the one for which he is spying. Examples of such illegals include Rudolf Abel, who operated in the United States, and Gordon Lonsdale, who was born in Russia, claimed to be Canadian, and operated in Britain. Famous Soviet "illegals" include Richard Sorge, Walter Krivitsky, Alexander Ulanovsky, and Anna Chapman, who was also known as a sleeper agent.
Comparison of illegal and legal resident spies
The advantages and disadvantages of legal resident spies mostly mirror the disadvantages and advantages of illegal resident spies. A legal resident spy has the advantage of diplomatic status, but the disadvantage of being a known foreigner to the host country and one of just a few official diplomatic staff, whose intelligence status is thus easy for counterintelligence agencies to discern. On the other hand, an illegal resident spy has the advantage of being unknown as a foreigner to the host country and one amongst millions of the country's ordinary citizens but the disadvantage of not having diplomatic immunity to fall back upon.
A legal resident spy has opportunities to meet high-level personnel of the host country as part of "official" business, and an illegal resident spy does not. However, conversely, illegal resident spies have easier access to a wide range of potential sources who would be put off by having to approach and deal with an openly foreign official and indeed need not even reveal to those people what country the spy actually works for.
Also, an illegal resident spy can stay in the host country when diplomatic relations break down, whereas legal resident spies are forced to leave with the diplomatic mission. A legal resident spy is easier to pay, since the salary can be openly incorporated into the diplomatic payroll, whereas making arrangements to pay illegal resident spies can be difficult, sometimes involving ruses that are more expensive and complex to administer than paying a diplomatic official would be, such as paying a host country organization or corporation to allow the illegal resident spy to pose as a member of its staff and be nominally paid by that organization/corporation.
A legal resident spy has full and aboveboard access to embassy facilities for secure communications, meetings, and other services. An illegal resident spy has little to no access to such facilities, and communications arrangements are thus more difficult and time-consuming. An illegal resident spy will usually have a falsified biography, whereas a legal resident spy may suffer from having an official biography documenting their diplomatic career and providing useful clues to counterintelligence services about their intelligence activities and connections.