A king of infinite space
To me [Denmark] is a prison.
Why then your ambition makes it one. 'Tis too narrow
for your mind.
O God, I could be bounded in a nutshell, and count myself a
king of infinite space—were it not that I have bad dreams.
Which dreams indeed are ambition, for the very
substance of the ambitious is merely the shadow of a dream.
Denmark isn't a place, it's a state of mind, and Hamlet feels like a prisoner there [see THERE'S NOTHING EITHER GOOD OR BAD, BUT THINKING MAKES IT SO]. King Claudius's foolish spies, Rosencrantz and Guildenstern, can't imagine what's wrong with Denmark—it looks like a fine enough place to them. Perhaps, they guess, Hamlet just resents his stepfather's rise to power, which has kept Hamlet from the throne; or perhaps Hamlet thinks Denmark too puny a kingdom to rule anyway.
Hamlet replies that the space inside a nutshell would be a kingdom enough if it were an untroubled kingdom. Kingship is merely an idea, a symbolic form; but the idea has been poisoned by the deeds of the current king and queen of Denmark. Haunted by those deeds as well as by the ghost of his father, Hamlet's world is a bad dream. The dim-witted Guildenstern can only insist glibly on his clichéd notion of a prince's vaulting ambition.