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 agents should not be confused with law enforcement officers who wear plainclothes. This method is used by law enforcement and intelligence agencies. To wear plainclothes is to wear civilian clothes, instead of wearing a uniform, to avoid detection or identification as a law enforcement officer.