In the process of making repairs to the holodeck, Barclay inadvertently uncorks the program of Professor Moriarty (Daniel Davis), the holodeck character that somehow achieved self-awareness in second season's "Elementary, Dear Data." Moriarty says he has been aware of the passage of time during his program's state of hibernation and demands to speak to Picard, who promised to investigate a way to free Moriarty from the confines of the holodeck.
Moriarty, however, remains a mysterious miracle of technology, and Starfleet's best programmers have not figured out a way to regenerate a holodeck matrix outside a holodeck. But Moriarty is so sure of his existence that he demonstrates mind over matter — and to everyone's astonishment, steps right off the holodeck and into the corridor of the Enterprise.
"Ship in a Bottle" is a fun ride that takes the "holodeck runs awry" motif and puts a welcome and original spin on it, with some cleverly brilliant twists of the plot. The results are as sly and imaginative as "Fistful of Datas" was tedious and forgettable. This is a bona fide sci-fi outing that considers the nature of existence for a character who is genuinely curious about the universe and is looking for a way to appease that curiosity — and who will not be fully satisfied until someone finds a way to get him off the Enterprise, along with doing the same for his beloved companion, Countess Regina Bartholamew (Stephanie Beacham), who is still trapped in the holodeck. "No" is not an option.
But things are not as they seem. Data discovers that Moriarty didn't actually step off the holodeck, but instead used clever sleight of hand to make it appear so. Picard, Data, and Barclay are actually still on the holodeck, trapped in an elaborate simulation of the Enterprise that Moriarty devised in order to manipulate the entire situation (Picard unwittingly gives his access codes to the holodeck version of the computer, which in turn gives them to Moriarty, who uses them to take control of the ship.)
If there's perhaps an unsung moment in this episode, it's the reaction of the simulated Geordi as he listens to Data explain to Picard that the entire engineering deck is a simulation — including Geordi. It's simultaneously funny, sad, and weirdly eerie. It's like watching holo-Geordi as he falls through the rabbit hole; surely he wasn't designed to be self-aware, but merely an elaborate copy of Geordi based on personnel files and carefully programmed responses. And yet in this moment, it's like he has become self-aware by being informed he's not real, because the program is forced to deal with a reality it wasn't designed for. Holo-Geordi's reaction is one of confused, disquieted silence — as if that's all the program can do once confronted with this feedback loop. LeVar Burton sells it.
Apart from the interesting philosophical dialogue about Moriarty's state of existence, "Ship in a Bottle" (a great title, by the way) is just a plain good time, using storytelling trickery to good effect. While I will always resist the unlikely notion that the holodeck is so flawless that it is utterly indistinguishable from reality, this episode takes that conceit and executes it wonderfully, establishing some narrative rules that it then doesn't break. (Note how the editing rhythm never cuts to the typical external view of the Enterprise in between scenes as long as we remain inside the holodeck.)
And I liked the appropriate turn of tables where, once Picard and Data realized they've been duped by Moriarty's illusion, they then use the same trick on him, creating a holodeck within a holodeck, and then giving him exactly what he wants — an escape to a "real world" by creating the illusion of a world outside of the holodeck, even though he never leaves it. Ultimately, Moriarty and the Countess (who also achieves self-awareness, somehow, thanks to Moriarty — a point the story unfortunately never adequately deals with) are able to tour the cosmos inside the confines of a computer program that runs inside a little cube. Picard's closing line on the nature of reality provides the story a perfect note of whimsy, suggesting our own reality may simply be built upon perspectives stemming from the knowledge available to us: "All this might just be an elaborate simulation, running inside a little device, sitting on someone's table."