My wife is reading a novel where one of the characters is facing execution for deserting the British army during World War I. Was the penalty for desertion really death?
Yes, executions took place but they are, by no means, nearly as common as the 'popular narrative' would like to imply. There were 306 executions in the entire British armed forces over the course of the war; this is in comparison to about 100,000 soldiers being medically diagnosed as 'shellshock', the thing people were supposedly shot en masse for. People executed for cowardice/desertion weren't executed because they were curled in their trench during a bomardment and were terrified; in general the people executed for cowardice were people who abandoned their post entirely, which led directly to dozens or god forbid hundreds being killed in a raid, and were miles away from the trenches hiding out somewhere. This practice was carried out in ww2, Vietnam, and to this day even.
Even when a man was found deserting he was not likely to be given a death sentence though. Even better even if they were given the death sentence only 10% would actually have their sentence carried out. That means that, yes, 306 Commonwealth soldiers were killed for 'cowardice' but there were 2700 others given that sentence who were let off and 20,000 British Commonwealth overall who were caught and found guilty of 'cowardice'/desertion. So proportionally only 15 out of every 1000 men found deserting was executed for it. Hardly the epidemic of executions popular narrative.
We have similar stories for the other powers. Germany had 150,000 deserters throughout the war and of those "only" 18 were executed. 24 Americans were sentenced to death for desertion but none had their sentence carried through. The French were the most kill-ey with 600 executions themselves compared to tens of thousands of those caught deserting.