A resident spy in the world of espionage 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. What the U.S. would call a "station chief", the head spy, is known as a rezident (резиде́нт) in Russian.
In the former Soviet Union and Russian nomenclature, there were two types of resident spies: legal'nye rezidenty (легальные резиденты, legal resident spy) and nelegal'nye rezidenty (нелегальные резиденты, illegal resident spy). In U.S. 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 their country's embassy). They are an official member of the consular staff, such as a commercial, cultural, or military attaché. They have diplomatic immunity from prosecution and cannot be arrested by the host country if suspected of espionage. The host country can expel such a person, requiring them to return to their home country as persona non grata.
An illegal resident spy operates under non-official cover. They cannot claim immunity from prosecution when arrested. They may operate under a false name and have documents purportedly establishing them as a national of the country, or from a different country than the one for which they are spying. Examples of two famous Soviet "illegals" are Rudolf Abel, who operated in the United States; and Gordon Lonsdale, who was born in Russia, claimed to be Canadian, and operated in Britain. Other famous Soviet and Russian "illegals" include Richard Sorge, Walter Krivitsky, Vasily Zarubin, Alexander Ulanovsky, and Anna Chapman, who was also known as a sleeper agent.
The advantages and disadvantages of legal resident spies are generally the reverse of those for 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. Their intelligence status may be easy for counterintelligence agencies to discern or suspect. On the other hand, an illegal resident spy has the advantage of being unknown as a foreigner to the host country, and one among millions of the country's ordinary citizens. The disadvantage is the lack of diplomatic immunity to fall back upon in case of arrest.
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.
Also, an illegal resident spy can stay in the host country if diplomatic relations break down. Legal resident spies are forced to leave with the diplomatic mission. A legal resident spy is easier to pay, for the salary can be openly incorporated into the diplomatic payroll. 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. Espionage agencies may arrange to pay 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. A legal resident spy may be at risk by having an official biography that documents their diplomatic career and provides useful clues to counterintelligence services about their intelligence activities and connections.