They can’t prevent you from doing anything, but you can agree not to and agree to consequences if you don’t.
Whether this is ethical or not is another (and important) question but that’s the legal framework to it.
Whether this is ethical or not is another (and important) question but that’s the legal framework to it.
*For example, in right-to-work states, employers can't agree to hire only union labor. Strange that that is prohibited, but an omerta imposed on workers is not.