Government officials in the United States enjoy broad immunity from personal and criminal liability for "official" actions.
However, even the sitting U.S. President is not immune to being tried for crimes committed "unofficially". Yet I can imagine an official making a colorable argument that any action was performed in an "official" capacity – especially when that official is the government's chief executive. Take an extreme hypothetical: The President murders someone in cold blood. Rather than evade detection for the crime, and rather than raising traditional defenses at trial, he simply declares, "I killed that person in my official capacity." After all, the President orders extra-judicial killings all the time.
Take the hypothetical down the line to beat police officers, who (as a whole) often kill people in their official capacity, and who claim they are "never off-duty."
What laws determine how claims of immunity for "acting in official capacity" should be adjudicated?