Then the foreign powers should declare war and they'll be subject to the Geneva convention. Covert action that is illegal in the target country has always made operatives subject to the local laws. If you want to be treated like a soldier, wear a uniform and fight in a declared war. Otherwise you're subject to the rules for spies.