McKay and Zelenka are trying to repair the drives to make a jump into hyperspace, and Sheppard wonders how likely it is they can steal the ZPMs from the Replicators. McKay suggests they'll need help: Dr. Weir.
McKay proposes they use Weir's nanites to hack into the Replicator systems to pull the mission off. Rodney assures them that he can shut down Weir's nanites if the Replicators try to take them over… although that will kill Weir. Sheppard orders them to start the mission immediately and tells Teyla to stay behind to take command… and abandon them if they're not back in 12 hours.
McKay finishes repairs and the team takes a Puddle Jumper to the Replicator world. Meanwhile, Sam and Lee arrive on a planet in the Pegasus galaxy to rendezvous with the Apollo. They go ahead with Sam's plan to scan for Atlantis through the gate network.
Sheppard's team arrives at the Replicator world but McKay warns that they've burned out the systems although he might be able to repower using the stolen ZPM. He starts to hack into the Replicator systems using Weir's nanites and Sheppard and Ronon go out to get the ZPM under Weir's instructions. She guides them past the guards to the ZPM storage chamber where they grab a pod and get back to the Puddle Jumper. However, McKay reveals that he's found a deactivated command code to attack the Wraith, and he can modify the code to reactivate it and pit the two sides against each other. However, they have to wait until the Replicators next share programming, and McKay doesn't know how long until that occurs. When Sheppard refuses, McKay comes up with a plan to store the reprogramming sequence until later. However, the computer core is deep inside the Replicator city and heavily guarded. McKay and Weir assert that they won't have another chance.
McKay alters the Jumper's cloak into an anti-Replicator detection field but Sheppard commands him to stay on the Jumper as backup to activate Weir's kill-switch if the Replicators start to take control of her.
The Apollo continues its search without success, and Sam and Lee warn it could take a long time.
The Puddle Jumper lands atop the computer core center and they cloak, then McKay gives them a plug-and-play unit to stick in. Elsewhere in the city, the Replicator leader Oberoth picks up the anomalous cloak readings and sends a squad. The squad disintegrates when they hit the field, and Sheppard plugs in McKay's device. Nothing happens and the Replicators slowly make their way through the field by sacrificing themselves to adapt to it. McKay tries to talk them through reprogramming his device while the Replicators finally gain immunity to the field. Weir warns that Oberoth has identified them and goes out on her own to intercept them. The others consider hitting the kill switch and finally Sheppard gives the order, but nothing happens. McKay realizes that Weir is probably exerting control over her nanites.
Weir intercepts Oberoth, touches him, and establishes contact over the Replicator Collective. Sheppard completes the reprogramming just as the Replicators enter… and freeze. McKay warns that since Weir is in contact with the Collective, they are more likely to take control of her. Oberoth boasts that he can feel her weakening.
Sheppard and Ronon get out and head back for the Puddle Jumper, but the Replicators come back to life and take the others prisoner. Oberoth visits the prisoners in their cell and tells them that they are "repairing" her to take control. He plans to interrogate them to determine the location of Atlantis since they weren't able to get it from Weir. he proceeds to "interrogate" Sheppard but is unable to do so. "Sheppard" turns into Weir, who explains that she reprogrammed them to believe they had overpowered Weir. She's still in control but realizes she can't escape even if the others do.
The others realize what's going on and start looking for her, even as Oberoth partially breaks her control. Sheppard and Ronon find her but Weir warns she can't keep him frozen much longer and tells them to leave without her. They have no choice but to leave as the Replicators really come back to life and capture her.
Sheppard and Ronon get back to the Puddle Jumper and they lift up, but McKay is working to hook up the ZPM and a cruiser intercepts them. Fortunately, the Apollo arrives and opens fire, bringing them aboard. They're unable to find Weir's signal and recover her. Once aboard, the Apollo escapes into hyperdrive.
Back aboard Atlantis, they look for habitable planets that Weir didn't know about. They find one and hyperjump to it, and Sheppard manages to land the city on the ocean despite the power drain on the ZPM.
Later, Teyla considers Weir's private possessions as she packs them up. McKay manages to hook up the Stargate and they reestablish contact with Earth. They also determine that the Replicators are now attacking the Wraith: their plan succeeded.
Sam talks with Sheppard and he thanks her for their help. She passes on Landry's condolences for Dr. Weir and Sheppard insists he hasn't given up hope.