Most prosecuting attorney positions in a District Attorney, or State Attorney General's office are full time salaries positions that prohibit individuals holding those positions from having any other legal employment. They are also, often, conceptually a division of state government, even if the DA is locally elected. So, any criminal defense engagement in the same state court system would also be a conflict of interest, and the reality of joint task forces discussed below would also make almost any federal case criminal defense engagement in the same state a conflict of interest in most cases because state prosecutors would gain confidential information about pending federal criminal prosecutions (and vice versa).
In theory, a criminal defense engagement in the next state over, for example, say, in Gary, Indiana for a prosecutor employed in Chicago, Illinois, would not be a conflict of interest, but it would still be prohibited in most cases because the prosecutor is a full time salaried employee whose full efforts are required to be devote to that position. (In practice, de minimis civil transactional work for the assistance of friends and family members, even for a small fee, or representation of such persons in small civil lawsuits would probably be tolerated, however, and maybe even a defense of a civil ordinance violation like a traffic ticket brought by a separate local government as discussed below, for a friend or family member for free, might be tolerated.)
Local governments such as cities, towns, and counties, however, sometime have an office separate from the DA's office or State Attorney General's office often called a city attorney, town attorney, or county attorney, who works part-time on a contract basis for that government and has limited authority to prosecution violations of that local government's own ordinances in the name of that governmental entity, rather than on behalf of the People as part of the state government.
In those cases, it is generally ethically permissible for the city attorney (for example) to serve as a criminal defense attorney in cases outside that city that do not otherwise pose a conflict of interest from having been adverse to various criminal defendants in the city attorney role. But there might be a conflict of interest, if, for example, there was a joint task force of the city attorney, the local DA, and the federal assistant U.S. attorney to prosecute people in a coordinated fashion on federal, state and local charges of various kinds, in connection with a rash of gun violence. And, if one of the city attorney's clients were arrested for an ordinance violation in the city, a non-conflicted counsel would have to be retained by the city for that case.
Often, in those cases, however, even though it is not a prohibited conflict of interest, the lawyers involved would view a criminal defense representation as a "business development conflict" that would risk non-renewal of the city/town/county attorney position if undertaken.
Incidentally, government attorneys, unlike almost all other government employees, are usually employees at will, as a matter of legal professional ethics, unlike almost all other fixed term contract or civil service employees, even if they have other contractual or civil service employee rights.