To go "undercover" is to avoid detection by the entity one is observing, and especially to disguise one's own identity or use an assumed identity for the purposes of gaining the trust of an individual or organization to learn or confirm confidential information or to gain the trust of targeted individuals in order to gather information or evidence. Traditionally, it is a technique employed by law enforcement agencies or private investigators, and a person who works in such a role is commonly referred to as an undercover agent.
Undercover work has been used in a variety of ways throughout the course of history, but the first organized, but informal, undercover program was first employed in France by Eugène François Vidocq in the early 19th century, from the late First Empire through most of the Bourbon Restoration. At the end of 1811, Vidocq set up an informal plainclothes unit, the Brigade de la Sûreté ("Security Brigade"), which was later converted to a security police unit under the Prefecture of Police. The Sûreté initially had eight, then twelve, and, in 1823, twenty employees. One year later, it expanded again, to 28 secret agents. In addition, there were eight people who worked secretly for the Sûreté, but instead of a salary, they received licences for gambling halls. A major portion of Vidocq's subordinates were ex-criminals like himself.
Vidocq personally trained his agents, for example, in selecting the correct disguise based on the kind of job. He himself still went out hunting for criminals too. His memoirs are full of stories about how he outsmarted crooks by pretending to be a beggar or an old cuckold. At one point, he even simulated his own death.
In England, the first modern police force was established in 1829 by Sir Robert Peel as the Metropolitan Police of London. From the start, the force occasionally employed plainclothes undercover detectives, but there was much public anxiety that these powers were being used for the purpose of political repression. In part due to these concerns, the 1845 official Police Orders required all undercover operations to be specifically authorized by the superintendent. It was only in 1869 that Police commissioner Edmund Henderson established a formal plainclothes detective division.