Petr and Kristine are horrified when their son Thom vanishes from his bed. Despite the doors and windows being locked he is, simply, gone. They are not surprised because this is just the latest in a series of disappearances of children. Petr points out that even though he is the head of the village they are not immune to the disappearances.
Out in the darkness of space the TARDIS materialises near a Century-class space ship, The Castor. It is showing no life signs but no signs of damage. His interest piqued by this and other little signs the Doctor materialises the TARDIS on board.
The ship is apparently in a night cycle, with the lights dimmed. The ship's computer does not show signs of a malfunction but there are hundreds of corpses aboard. It is apparently a huge prison vessel. Deck after deck is full of cells and all seem to contain a dead body. The artificial atmosphere has mummified the corpses but the Doctor thinks they are possibly centuries old. The crew, too, are dead; many still at their stations as if whatever happened was over in an instant. Curiously there are also research laboratories on board.
As the daylight cycle kicks in and the ship is lit up by bright lights they find a more high-tech room full of computer terminals. Using one of these, the Doctor finds a map of The Castor showing two life signs on board. One is human (Martha) and the other is unknown. Further into the map he discovers another two life signs. The first is transitory, apparently flickering in and out of existence, but the second is huge and complex, giving too much information to process. It is also between them and the TARDIS.
Naturally the Doctor is keen to investigate. They back track to where they left the TARDIS in an empty corridor only to find when they get there that the corridor is gone. It has been replaced with an enormous forest.
Deep inside the forest it is early morning. Saul has left his village to check his traps and is revelling in the beauty of the scenery: the distant mountains; the canopy of leaves; the village by the lake; the island in the heart of the lake. There are two things bothering him: his desire to travel beyond the confines of the forest region that he knows so well and the unnatural mist that is forming on the edges of the lake.
Saul collects a pitcher of water and delivers it to the home of the Dazai ( an aged and ageless wise woman who lives on the edge of the village). Every morning he repeats this ritual and she often questions him about his thoughts and his relationship with his brother, Petr, the village leader. On this particular morning she again suggests that he is troubled by his desire to visit new lands and settlements. She also suggests that she has a feeling that this day will bring something new into their lives.
Martha and the Doctor stand within the forest, speculating on how it appeared on the space ship. Martha suggests it is virtual reality or they have travelled through a wormhole but the Doctor dismisses both ideas. One tree, however, seems to be made of metal and still bears the imprint of the outline of the door they passed through in the ship's corridor. The Doctor expresses an urge to explore on the pretext of looking for the TARDIS. He says they will only walk for five minutes and if they haven't found it they will return to this same place.
Two hours later they are still wandering around but Martha thinks this is because they are going in circles as she recognises a distinctive stump that they pass several times. A number of things perplex the Doctor. One of these is a wild boar that they encounter, which is not quite alive in the same way that the two of them are. Another is the range of trees in the forest: half are drawn from all regions of the Earth and the other half he has never seen on any planet.
When Martha demands they return to their starting point the Doctor agrees, with the unfortunate caveat that his foot is caught in a trap. Nothing she can do will free him.
Saul has returned to his traps and soon comes across the two travellers. At first he assumes they are traders from the mountains who have got lost. Before he can approach them he becomes aware that something huge and threatening is coming towards them. Saul hurries forward and flicks a hidden catch on the trap, freeing the Doctor and indicating a huge red-eyed beast in the nearby trees. It has scaly hide and slender limbs. The three of them carefully back away before hurrying into the safety of another patch of forest.
Eventually they reach the edge of the forest and make their way to the village. Saul says the newcomers must meet his brother, the village leader. Martha notices that there is no road into or out of the village. Perhaps this is because there is no outside world, but the clear blue sky and the distant mountains suggest otherwise. The Doctor tells Saul that he needs to explain to his brother that the village, forest and their reality only came into existence a few hours earlier.
Jude, Saul's twelve year old daughter, is at school. She is bored, as usual, and finds herself wondering about death. Looking out of the window she thinks she can se a figure in the fog by the lake and recognises it as Farah, the most recent child to mysteriously vanish from the village. Farah is looking at the school but she is mysteriously drained of colour. When her teacher distracts her she turns back to find that the girl and the fog have gone.
The village, like the forest, seems to be made up of an eclectic jumble of styles. There are architectural influences from middle England to the Andes, Tibet to Japan. In addition, for all its isolation the villagers are strangely incurious about the arrival of strangers.
Petr is amused rather than outraged by the Doctor's assertion about the village's recent appearance from nowhere. He says that the village dates back for hundreds of years and there are written records to prove it. He also shares the news of the recent disappearances of eight children from their homes. When the Doctor asks the name of the village Petr is puzzled as if this question has no meaning but eventually says it is called Herot. He also cannot answer questions about the region or country where the village is situated. Later Martha questions Petr's wife Kristine about visitors from the outside world and learns that they arrive occasionally but no one from the village ever travels the other way. Saul interjects that this is due to a decree from his brother forbidding it. He does offer to take Martha into the forest. Before she leaves Martha learns from Kristine of the villagers' belief that if their missing children return then the village itself will be destroyed.
In the forest Saul tells Martha that he is the only villager who shows any interest in going beyond their immediate environs, but whenever he goes too far monsters like the one Martha saw, and worse, send him back. They seem to be coming closer to the village, too. Similarly no one may visit the island in the lake but no one questions this either.
The Doctor visits the Dazai in her home. He learns that Dazai is an honorary title passed from mother to daughter, or so people think. There are rumours that she is the only one and has been there since the creation of the village. She asks the Doctor some searching questions about the nature of reality, even asking if he can prove his own existence. She then shows him a book case stretching the height and width of her room containing a record of all of the significant (and many minor) events in the village's history. Pulling books at random from the shelves the Doctor finds that some seem blank but fill with writing as he looks at them.
Martha and Saul are attacked by a giant monster in the forest. Part dragon, part insect it flattens trees in its attempt to reach them but they manage to evade it, running blindly through the trees. Martha finds that she has lacerated the skin on her hands.
After leaving the Dazai the Doctor encounters Jude, who has been tracking him round the village. He is skipping stones across the lake. As the two begin to make friends they see Martha and Saul returning through the twilight to the village.
At Petr's house Kristine quickly, almost miraculously, heals Martha's cuts with a local remedy before the Doctor draws his companion to one side. He explains that they need to leave this reality as soon as possible and get back to the ship. He is afraid that as night falls the village and its surrounds will snap out of existence. Calculating the distance that he and Martha have walked from the forest he is afraid that they are several miles from the space ship and if the village disappears they will find themselves in deep space. This theory is supported by Martha's observation that she left the village with Saul and headed south but returned from the north as if space were somehow folded on itself. The Doctor reasons that this is to conserve energy and explains why they seemed to be going round in circles in the forest earlier when they were heading in a straight line. It reminds Martha of a dream which supports the Doctor's theories. But whose dream is it? He wonders if the missing children have just been lost like data on a broken hard drive but he says the only way to get them back is to return to The Castor and work from there.
The Doctor has explained to Martha that the name Herot was the name of a battle hall in an old poem. It suggests that a lot of Earth culture has been used to derive the basis of the village just as the people also seem to conform to the archetypes: Petr is the thoughtful leader, Saul is a brave hunter, there is a wise old woman. Their conversation is interrupted by the frantic arrival of another distraught parent as another child goes missing. Rushing to their house the Doctor can find no evidence of a break in. He asks Saul to take him back to the forest.
Saul leads them back to the place where he met them earlier in the day. They have just reached that point when they hear a scream Saul's daughter, Jude, has crept from her bed and followed them and is being threatened by a monster. Saul draws both of his swords while Jude runs to the Doctor's side. The Doctor uses a high pitched whine from his screwdriver to distract the beast while all four flee but it chases them. The Doctor uses the screwdriver to overlay the reality of the space ship onto the forest. As Saul battles with the monster, the other three run to the corridor on The Castor but Jude turns back to see her father falling. Martha notices that the man is down, at the mercy of the creature, and runs back to help him.
Back in the village a thick fog has filled the streets. Within it apparitions of the missing children are appearing, accusing their parents of poor parenting.
Jude wakes up in the dark. She finds herself in a strange world, made of metal, where the lights switch themselves on automatically. She remembers that she had been on her way to help her stricken father when she fell into this new reality. Making her way through the impossibly long corridors of the space ship she becomes aware that there is something else moving in the darkness.
Martha's attempts to divert the monster from Saul are not going well and she is about to be cut down by its sharp tail when Petr arrives, brandishing a sword, and drives it off. This gives Saul the chance to recover and help his brother drive the creature off. Martha has to explain that the Doctor has gone onto the ship, Jude has vanished and that she came back into danger to help Saul. He is cheered by this news, hoping that Jude is with the Doctor. More monsters make themselves heard in the forest. Saul thinks they mark the edge of the world and they are closing in all the time.
The Doctor and Jude eventually find each other and the doctor tries to explain where they are, eventually showing her the blackness of space through a window. On a computer console he shows her a map of the ship and their life signs. She notices the flickering, barely registering, signal of another life and tells him that she constantly felt she was being followed as she wandered around but could see nothing.
The Doctor decides that the terminal he is using is too limited and decides to make for the main science hub to look for answers. On the way they suddenly encounter a dark creature and the Doctor walks into it, and is swallowed up. He experiences at first hand the memories of a convicted murderer, witnesses the crime, trial and sentence. The killer, Ben Abbas was sent to The Castor and was forced to relive his own crime until the memories seemed to sheer away. The other prisoners were going through similar torment and even the guards and scientists lived in a world of constant dread until violence suddenly broke out, fires were lit and the angel of the shadow of death swept through the corridors of the space ship devouring everyone.
In the village hall Saul has to explain to his wife that Jude has gone, hopefully with the Doctor who Martha promises will sort everything out. She is determined to do something herself. When the Dazai says that there is a god-monster in a cave on the island in the middle of the lake, and that if it is slain by a hero then all is not lost, she decides to go with Saul and Petr to confront it.
Martha and the brothers return to the village to find it completely shrouded in mist. They see a figure, Petr's son Thom, but his eyes are empty and dull. Martha hurries Petr on but every house is empty. Eventually they arrive at the village hall. The Dazai has gathered everyone there and hung the building with lights.
The Doctor emerges from the dark angel and tells Jude that he has just experienced the life of Ben Abbas, the last man on the ship to die. He thought the angel was trying to give him an insight into what went on during The Castor's time as a prison correction centre. The entity itself is the distilled essence of humanity's evil. It was raiding his most private memories and the experience would have been enough to kill a human.
Above the village there is a tunnel in the mist showing a blank and starless sky. Martha and the brothers are making their way to the lake when the spectre of Thom appears appealing to his father. However, it is Saul he is addressing. Saul tries to explain and apologise to Petr but the village leader attacks his brother, threatening to kill him.
As the Doctor rushes down ever-darkening corridors he tries to explain the futility of The Castor project. Evil is the result of choices: removing the memories of past evil does not remove the capacity to choose evil again. Perhaps Jude's world, he thinks, is a place where choices can be made as part of a lab, an arena and a theatre all rolled into one. He wonders for whose benefit it was created.
Once Thom's image has gone Petr seems to come to his senses. He stops trying to kill Saul and the trio find some moored boats. As they row across the water they are attacked by vicious creatures, fighting them off with difficulty and only surviving when one of the beasts is wounded and the rest turn on it in a feeding frenzy. The boat is destroyed in the attack and the three of them swim to the shore of the island. The two men seem united by a bond made of pride at their achievement joined with a sense of co-operation. Neither has wondered how they will get back again.
At the entrance to the science hub the Doctor and Jude encounter the dark angel again. Trusting to his own inner strength and Jude's innate goodness he takes her into the creature again. The angel seems to be tempting her to revisit parts of her life and make easier but more evil choices. She refuses. Suddenly they are on the other side of it and decide it looks less threatening now that they have passed through.
In the centre of the hub, suspended at the centre of wires and tubes, is some sort of creature with huge globular appendages. The Doctor steps up to it saying, 'I'm so sorry.'
Martha approaches the cave on the island. Inside is a great stone door and beside it stands the Dazai. She says it is possible to walk through an archway of trees on the shore furthest from the village and end up in the cave. She says she goes there often to think. When Martha asks why she let them cross the dangerous lake the Dazai tells her it was to let the brothers work out their differences and come to some reconciliation. She says the stone door has never opened for her but thinks it will be different for Martha because she is from a different world. Martha presses her hand to the door and it slides open. She steps through into the science hub of The Castor and runs to the Doctor to throw her arms around him.
A lengthy dialogue ensues between the Doctor and the creature. It says it allowed Jude and the Doctor to survive because of Martha's bravery in staying in the unreal world. It tells how it was a traveller between dimensions until humans caught it and discovered its ability to soak up memories, emotions and instincts. They tried to use it to suck the evil out of men to make them good again. The creature could not stand the evil that flowed into it and had to create the dark angel as a way of expelling it. It took on a life of its own and butchered the inhabitants of the ship. Left to itself the trans-dimensional creature created the village as a free space where humanity could be explored as thought made flesh.
The Doctor is amazed that the original templates have developed free will and can exist, like Jude, away from their original environment. He recognises that the Castor has drifted away from the lighter regions of space and is running out of energy. Unable to sustain the village and its people the creature has had to cut back on the size and scope of the land and has had to remove the most energy-expensive humans - the children. Now the creature says it is too tired to maintain the experiment and may let it blink out of existence.
Martha also realises that the Dark Angel is growing in size and is edging nearer to the people in the control room. The Dazai has entered the room however. When the creature repeats how tired it is the Dazai contradicts it and says it is wrong that such an amazing creature should give up. The Doctor says he will pilot the ship to a brighter part of the universe to provide more power. When the creature repeats it is losing control of the dark angel the Dazai steps forward, absorbing all of the darkness and evil.
Freed of the burden of guilt the creature agrees to maintain the existence of the village and opens a door in the cave on the island, freeing the children into the welcoming arms of Saul and Petr. They lead the children across a newly formed spur of rock that links the island to the shore. The Dazai says she cannot go with them but must live in the forest while she battles the demons within her. As she departs the forest and village fade, leaving the Doctor and Martha alone on the Castor.
The Doctor says that the Dazai told him that this is not the first time that this has happened and that these events are likely to happen again. He hopes that when it does he has someone as brave as Martha to help him.