The Doctor teleports into a surreal castle with no clue where he is. As he explores, he is relentlessly pursued by a mysterious creature called the Veil, which will kill him if it catches him. He can only stop it temporarily by confessing truths he's never told.
There are ominous signs of previous prisoners, but aside from himself and the Veil, he is utterly alone. He narrates his experiences to a mental figment of Clara.
Following a line of clues, he eventually comes to an impasse, faced with a wall that is 400 times harder than diamond. With the Veil only moments behind him, he punches the wall repeatedly with his fist... and the creature fatally touches him before collapsing in a pile of clockwork.
The Doctor takes a long time to die, however, and crawls back to the teleporter room, where he uses his body to power the teleporter to recreate himself from the saved copy. It soon becomes obvious that there was never anyone else here but the Doctor.
The horrific cycle continues for billions of years, until the Doctor's fist finally shatters the last bit of wall blocking the way out.
He finds himself on Gallifrey, and he tells a young boy to tell the people in the Citadel that he has returned.