The Doctor and Donna arrive in the 51st century at a planet-sized book repository simply called "The Library", summoned by an anonymous request for help on the Doctor's psychic paper. However, they find it completely devoid of humanoid life, and the Library's computers even claim as such, though when the Doctor widens the search for non-humanoid life, the Library's computers claim over "a million million lifeforms" exist. A Node, an information drone which presents a donated human face to the user to facilitate communication, warns them to count the shadows, which appear despite the lack of objects to cast them. They then see the overhead lights in front of them turning off one by one. Fleeing from this power cut, they find a small security camera which responds strangely to probing with the Doctor's sonic screwdriver, saying that "it hurts". The bot then warns them that "others are coming" and a team of explorers, led by archaeologist River Song, arrives. The team has come to ascertain the meaning of the Library's final communication, which states "4022 saved, no survivors". River Song seems to know the Doctor, has a diary with a cover matching the Doctor's TARDIS, and even possesses a sonic screwdriver. She also later displays knowledge of the TARDIS's "emergency programme one". She only admits that she will know the Doctor in his relative future, refusing to disclose more for fear of spoilers. Professor Song also recognises Donna's name, but avoids explaining why Donna was not present when she knew the Doctor.
Curiously, the Library's operations seem to be tied to the imagination of a young girl shown throughout the narration; she sees the Doctor and Donna through the eyes of a security camera when they first break into the central room, the exploration team appears on her television when the Doctor attempts to hack the Library computers, and books fly from the shelves when she fiddles with the television's remote control. The girl is under the observation of Dr. Moon, a child psychologist, at the request of her father. Dr. Moon is there to counsel her about her "fantasy" of the library, but Dr. Moon instead tells her that the library she imagines in her nightmares is in fact real, and her real world is a lie. He also states that there are people in her library who need to be saved.
Back in the library the Doctor organises the archaeology team to make sure the area is well lit as he explains that they are surrounded by Vashta Nerada, microscopic carnivorous creatures that disguise themselves as shadows to hunt and latch onto their prey. He notes that they are usually nowhere near as aggressive or numerous as the ones here seem to be. Before he can fully explain, however, a team member (Miss Evangelista) goes off to investigate something the others are ignoring and is stripped to the bone in moments. The Doctor and Donna learn that the exploration team wears communication devices which link to their nervous systems for thought-based communication. As a side-effect, these devices tend to retain an imprint of the user at the moment of death, creating a short-lived "Data Ghost" of that person's consciousness, which is capable of communicating with the living (being 'unaware' that it is dead) but eventually dissipates to the point where it simply repeats the last thing it said or nonsense.
The team's investigation is interrupted when a shadow of Vashta Nerada latches onto the pilot, Dave. Although the Doctor attempts to save him by sealing him inside his suit, the creatures manage to get inside, eat him alive, and then animate his suit in order to chase the other explorers. The Doctor attempts to teleport Donna back to the TARDIS while he leads the rest of the team to safety, but something goes wrong with the teleport and Donna fails to materialise properly. As the team races away from the possessed suit, the Doctor is horrified to find a Node with Donna's face on it, which claims that Donna has left the Library and has been "saved." The show ends in a cliffhanger as the Doctor is forced to leave the Node behind, but is trapped by the approaching suit on one side and the Vashta Nerada shadows on the other.
