"Undo" is a front end token that reverses the most recent command, if possible.
This token is equivalent to the menu command Edit Undo.
You can only undo your most recent command. In general, you can undo the basic commands in the Edit menu as well as any typing you have done since your last action.
To execute a front end token, you typically evaluate a command of the form FrontEndExecute[FrontEndToken[token]].