In modern-day England, child psychologist Dr. Moon visits with a young Girl who has reported hallucinations where she sees herself in a gigantic library. She believes something has gotten into the library, something dangerous. The Girl can see herself in a room when she hears a banging noise at the door. Two people burst through the door and bolt it behind them: the Doctor and Donna. The Doctor seems to notice the Girl, steps forward, and apologizes to her.
The TARDIS materializes on a giant library planet. The Doctor shows Donna around and explains that the planet is The Library, with a copy of every book in existence stored and an index computer at its core. The Doctor is so impressed it takes a few minutes to notice that no one is around. Accessing a data port, he scans The Library for life forms and discovers only two humanoids: himself and Donna. However, when he expands the scan to include other life forms, the system detects over a quadrillion beings. They're interrupted by a voice, and go inside to find a Node. The Node is an electronic information device with a human face. It warns them it has recorded two messages from the Head Librarian. The first is that The Library is in shutdown and they should run. The second is to count the shadows.
The Doctor finally admits that he received a message on his psychic paper, an unsigned note saying to come to The Library. Suddenly the lights start going out and the shadows multiple. They run through a door into a room, bar it, and notice… a small floating security camera. The Doctor steps forward and apologizes to it…
On Earth, the Girl loses her connection to The Library as the security camera she was seeing through shuts down. She can still hear through the camera, and can hear the Doctor using his sonic screwdriver on it. She yells at them to stop and in The Library, the Doctor and Donna see her words flash on the camera's LED readout. The Girl tells her father and Dr. Moon that The Library has been breached.
The Doctor and Donna try to get information from another Node with a different human face. Donna finally realizes that the face is taken from a willing human donor and used to put a pleasing image forward to deal with patrons. The Doctor is more concerned with the shadows, as he notices one shadow that has no apparent source. As the lights continue to go out, the Doctor realizes that some of the shadows are moving. The Node says that the Library has been breached and others are coming. Suddenly a suited group of figures burst through the door. The leader opens her visor and greets the Doctor, seemingly knowing him. She introduces herself as Professor River Song, the leader of a group of archaeologists hired by Strackman Lux, who is present with his assistant Miss Evangelista.
The Doctor tells them to leave but they refuse, and Evangelista tries to get them to sign a personal experience contract signing over the rights to what happens to them to Strackman, who owns the planet. The Doctor and Donna both tear up the contracts. Song explains that The Library went into shutdown a hundred years ago and Strackman wants them to find out what happened. The Doctor warns them again that they have to leave, saying that all species have a fear of the dark but it's no superstition. The Vashta Nerada lurk in the shadows, and the Doctor says they have to generate as much light as possible to hold them back.
As they try to secure the room, Song admits that she summoned the Doctor through the psychic paper. She takes out a TARDIS-shaped diary and tries to determine what adventures the Doctor has had, and it becomes clear that she is for the Doctor's future.
Song's teammates tap into the security system and set off a telephone ringer. In her home, the Girl hears her phone ring but neither Moon nor her father notice anything. The Doctor accesses the security protocols and establishes contact with the Girl so that they can see each other on her television and their security monitor. They lose contact and the Doctor tries to power up the lights. As he does so, he tries to get a look at Song's diary but she warns him that she's under strict orders not to let the Doctor see it… orders from the future Doctor.
The Girl tries to get the Doctor and the others back on her television, and starts pressing buttons on the remote. In the room in The Library, books start flying off the walls but are otherwise harmless. Trying to determine the source of the signal, the Doctor finds a CAL security protocol and asks Strackman what it is. He admits that it has kept The Library in shutdown for a hundred years and they've only finally managed to override it enough to send a small party in. Song notes that one message was sent out: "4,022 saved: no survivors." They know that there were 4,022 visitors and staff at The Library when it shut down, but don't know how there could be no survivors if they were saved.
Miss Evangelista notices an open panel and wanders into an adjacent hallway. The Doctor and the others hear a scream and run to it. They arrive within seconds only to find that some unseen enemy has stripped Evangelista to the bone. Eerily, Evangelista speaks to them through the communicator on her suit, but Song says that it is just a data ghost. The communicators have a telepathic element and pick up thought processes and stores them. "Evangelista" tries to talk to Donna, but the mental recording quickly degrades as Donna looks on in horror. There's nothing they can do so the Doctor goes to find a lunch kit to demonstrate his theory. He also asks Song who she is to him, but she refuses to answer.
Dr. Moon talks to the Girl in private and changes tact, telling her that everything she has dreamed is real and it's the real world that is a lie. He says that the shadows are moving again, and she's the only one who can save the Doctor and the others.
While the Doctor scans the floor of their refuge, Song recognizes Donna by name but notes she hasn't met her in the future. She also admits that she mistimed the message and sent it to the Doctor before he knew her. Donna is concerned about where she will be in the future by the time Song becomes the Doctor's companion.
The Doctor is ready to demonstrate and says that the Vashta Nerada are flesh-eating creatures that appear as shadows. He's located some of them and tosses a drumstick to them: they strip it to the bone in less than a second. He notes that most planets have small groups of them but they're not usually aggressive. However, there's no way to stop them: you can only run away. Donna suggests they use the nearby shop's teleporter unit to escape.
As they start to leave, the Doctor notices that one of Song's teammates, Dave, has two shadows. He tries to seal the man's suit using his sonic screwdriver, while Song pulls out a sonic screwdriver of her own and seals the others' suits. The Doctor apparently succeeds and then takes Donna to the teleporter. He wants to get her to safety and the TARDIS defenses will only allow her through. Before she can object, he sends her away and she starts to materialize in the TARDIS… and then breaks apart into thousands of parts, all screaming in agony.
The Doctor returns to the group and notices that Dave's second shadow has disappeared. Dave talks to them, wanting to know what happened to the lights even though they're still on. The suit turns around, revealing that it is filled with the Vashta Nerada and they've already killed Dave. The "Dave" talking to them is only his mental processes recorded on the communicator. The Vashta Nerada move the suit and attack the Doctor, and Song yanks him free of its grasp. More "shadows" emerge from the suit and close in on the remaining survivors, but Song blasts a hole in the wall and they escape into The Library.
The Girl informs her father that Donna Noble has been saved.
The survivors find temporary refuge in the shelves. As the Doctor tries to boost the lights, he wonders why Song has a sonic screwdriver. She explains that his future self gave him one. Using his own sonic screwdriver, the Doctor determines that Donna didn't materialize in the TARDIS. He sees a Node… with Donna's face. It mechanically says that Donna has left The Library and is now safe.
The animated suit approaches them and they run down a hallway… only for the Vashta Nerada to cut them off ahead. The enemy closes in from both sides and the Doctor and the others have nowhere to run…
(to be continued…)