The defense of entrapment can be used when the government unfairly induces the defendant to commit a crime. The purpose of this defense is to prevent law enforcement officials from simply manufacturing crimes where they wouldn't have otherwise existed. The criminal law exists not only to protect civilians from one another, but also to protect them from unfair treatment by law enforcement officials and judiciaries.
The level of government involvement in crime can vary from the most superficial involvement to undeniable causation. For example, an undercover officer might solicit a drug dealer for drugs, or he might repeatedly and forcefully solicit someone who is not predisposed to sell him drugs until that person caves in. In the first case, the officer played a superficial role in the crime - the drug dealer was selling anyway and the officer simply exposed his usual behavior. The entrapment defense would probably not apply in this case, since the defendant was reasonably predisposed to commit the crime without the officer's involvement. In the second situation, however, the officer arguably caused the crime to be committed, when it might not have been committed otherwise. That's where the entrapment defense comes in.
It could be argued that entrapment should apply to any crime that is induced by government activity or, on the contrary, that no crime is defensible by the entrapment defense since the defendant did, in fact, commit the crime in question. In reality, the criminal law walks a middle line on this issue, preferring to judge whether entrapment is applicable based on whether a trap has been laid for the unwary innocent, or a trap laid for the unwary criminal.