The use of the Doctor's previous companions, in particular Sarah Jane and K-9, was first proposed in 2003 to the BBC. After the episode was produced, Elisabeth Sladen was approached by the BBC to star in a spin-off, The Sarah Jane Adventures, which also included K-9 in several stories. The episode was positively reviewed, with an Appreciation Index of 85% ("Excellent"), due to Sladen's appearance as Sarah Jane.
The higher-than-average intelligence of the children has aroused media attention - in particular, the attention of investigative journalist Sarah Jane Smith. While at first the Doctor feigns ignorance, when Sarah Jane discovers the TARDIS during the night, he is forced to admit his identity. Sarah Jane meets Rose and Mickey, much to the chagrin of Rose; they then find thirteen bat-like creatures asleep in Finch's office. Sarah Jane reveals a battered, inactive version of K-9 (pictured above), which - once repaired - identifies the chip oil as Krillitane oil. Rose, who was unaware he had past travelling companions and thought that she had "something special" with the Doctor, confronts him; he replies sadly that, while she can spend the rest of her life with him, he cannot spend the rest of his life with her.
The following day, the group returns to the school to investigate further. The Doctor confronts Mr. Finch, who confirms that he and the others are Krillitanes - a composite species that takes desirable attributes of the species they conquer. He attempts to subvert the Doctor, without success. Meanwhile, Sarah Jane and Rose try to unlock the programming on the school's computers; Mickey and K-9 remain in Sarah Jane's car for surveillance. With the Doctor's help, they discover that the computers - bolstered by the students' enhanced intelligence - are part of a Krillitane effort to solve the "Skasis Paradigm", a theory of everything. As the paradigm is nearly solved - which would allow the Krillitanes full control over time and space - the Krillitanes seal the school. Mr. Finch propositions the Doctor a second time, tempting him with the ability to save the Time Lords and override human mortality. With Sarah Jane's counseling, the Doctor refuses, and they run from Mr. Finch. Mickey crashes Sarah Jane's car through the school's doors and unplugs the computers, allowing the children to flee. The Doctor leads the Krillitanes to the kitchen; upon their arrival, K-9 opens fire on the oil barrels, destroying the Krillitanes, the school, and himself.
At episode's end, Rose, Sarah Jane, Mickey, and the Doctor are standing by the TARDIS. Sarah Jane declines a second chance of travelling in the TARDIS. Mickey says he would like to travel in the TARDIS instead, a suggestion of which Sarah Jane approves. She then asks Rose to stay with the Doctor and - if she needs help - to find her. Sarah Jane then gets a chance to part properly with the Doctor, who leaves her with a brand new K-9 as a parting present.
The episode went through several changes in production: working titles included "Old Friends" and "Black Ops", the latter being set in an army base. Davies requested that Whithouse set it in a school instead, mainly for simplicity, but also for a desire for the Doctor to masquerade as a school teacher. Additionally, the Krillitanes were to be named "Krillians" until the BBC found the name was trademarked, and Finch's forename was originally Hector, until the BBC found a real teacher by the same name, and renamed him Lucas. K-9's lights were intended to flash in sync with his lines, not unlike the Daleks, until Phil Collinson vetoed the idea. A scene that was cut was of Milo's brain being "shorted out" by the Doctor's rapidfire questions at the beginning of the episode, which was later alluded to in the episode.
The episode, originally in the second production block, was produced in the first block along with "The Christmas Invasion" and "New Earth". Two high schools in Wales were used for filming: Fitzalan High School in Leckwith was used on 23 August and 24 August 2005, for filming the first conversation between the Doctor and Finch, and for the playground, kitchen, and cafeteria scenes, and Duffryn High School in Newport, which was used between 25 August and 6 September for the remainder of the episode, with filming delayed due to asbestos being discovered in Duffryn High School's structure. The scenes in the schools utilised dozens of children as extras. Pick-up shots were later completed on 7 September and 8 September, with filming of the cafe scene delayed due to drunk and disorderly conduct from members of the public.