When Starbug managed to destroy a Simulant battle cruiser, its captain ordered his lieutenant to hack into Starbug's navicomp before they died. She uploaded a virus which locked the navicomp onto the nearest planet and prevented any course changes.
Kryten shut down any links to the rest of Starbug's systems, but couldn't purge the virus. He realised that the only option was to contract the virus himself and attempt to find an antidote. He had to shut himself down to focus on the antidote, but suggested that the rest of the crew watch his dreams.
His subconscious turned the struggle into a dream in which he was the drunken sheriff of a frontier town called Existence and the virus was a group of outlaws - The Apocalypse Boys. They demanded he leave town, at which point Kryten seemed to give up. Cat suggested that they should help him, so Lister wired up the artificial reality console to Kryten's mind.
Taking characters from the game "Streets of Laredo", Lister, Rimmer and The Cat rode into Existence and managed to save Kryten from the treacherous locals. They then sobered him up enough to remember why he was there. Brother Death, who seemed to be aware of his status as a computer program, deliberately spread the virus to the AR machine, erasing the special skills of the crew's characters. They managed to escape from the simulation, leaving Kryten to face his enemies alone. He recognised the Apocalypse Boys as the Virus and used his revolvers as a "Dove Program", which spread peace through his system and destroyed the virus.
He awoke on Starbug's upper deck and raced to the cockpit, uploading the antidote to the navicomp. Starbug plunged into the molten surface of the moon, but they regained helm control just in time to pull out of the lava and fly away (RD: Gunmen of the Apocalypse).