Ship in a Bottle (Star Trek: The Next Generation)

"Ship in a Bottle" is the 138th episode of the American science fiction television series Star Trek: The Next Generation, the 12th episode of the sixth season.

Set in the 24th century, the series follows the adventures of the Starfleet crew of the Federation starship Enterprise-D. In this episode, which continued a plot line from the second-season episode "Elementary, Dear Data", the fictional holodeck character Professor James Moriarty seizes control of the Enterprise in his quest to be freed to live in reality, outside the confines of a holographic environment.

Plot
Lieutenant Commander Data and Lieutenant Commander Geordi La Forge are enjoying a Sherlock Holmes holodeck program when they notice that a character programmed to be left-handed is right-handed. They ask Lieutenant Barclay (Dwight Schultz) to inspect the holodeck; as he checks the status of the Sherlock Holmes programs, he inadvertently activates the sentient Professor James Moriarty (Daniel Davis) character ("Elementary, Dear Data"). Moriarty wishes to escape the holodeck and was assured by the crew of the Enterprise that they would endeavor to find a way to do so, and is irritated by the lack of results. Captain Picard, along with Data and Barclay, assures Moriarty they are still working toward this goal, but Moriarty is dismissive.

Moriarty walks out the holodeck door. He explains this to the stunned Picard and Data by saying, "I think, therefore I am." Moriarty creates a companion for himself, the Countess Regina Bartholomew (Stephanie Beacham), by commanding the computer of the Enterprise to place another sentient mind within a female character of the Sherlock Holmes novels. Moriarty takes control of the Enterprise and demands a solution to get Regina off the holodeck.

While assisting La Forge, Data observes that La Forge's handedness is incorrect, just as they experienced earlier. Data determines that he, Picard, and Barclay remain inside the holodeck with Moriarty; everyone and everything that appears to be the Enterprise is part of a program Moriarty created. Picard realizes that he has unwittingly provided Moriarty with the command codes for the Enterprise. Moriarty takes control of the real Enterprise from within the simulation.

Picard programs the holodeck's simulation of a holodeck to convince Moriarty that he and Regina can be beamed into the real world, though they are only "beamed" within the holodeck's simulation. Moriarty, unaware of the ruse, releases control of the ship back to Picard. He and the Countess use a shuttlecraft given to them by Commander Riker to leave the Enterprise and explore the galaxy. Picard ends the simulation, and Barclay extracts the memory cube from the holodeck and sets it in an extended memory device in order to provide Moriarty and the Countess a lifetime of exploration and adventure.

Picard suggests that the crew's reality may be a fabrication generated by "a little device sitting on someone's table." Barclay gives an audible command to "end program" to test whether he is in a simulation, smiling when there is no response.

Academic study
The book Hailing Frequencies Open: Communication in Star Trek: The Next Generation by Thomas D. Parham, III says that "Ship in a Bottle" is an example of using interpersonal interactions to explore ontology. They found that several other episodes in the series used interpersonal interactions to explore philosophical concepts.

Reception
"Ship in a Bottle" was ranked the 21st of the 100 top episodes of all Star Trek by The Hollywood Reporter in 2016. In 2011, this episode was noted by Forbes as one of the top ten episodes of the franchise that explores the implications of advanced technology. In 2016, TIME magazine ranked Moriarty as the 5th best villain character of the Star Trek franchise.

In 2009, Io9 Gizmodo listed "Ship in a Bottle" as one of the worst holodeck-themed episodes of Star Trek.

In 2012, Wired said this one of the best episodes of Star Trek: The Next Generation.

In 2015, The Hollywood Reporter noted this episode's presentation of Moriarty setting out to explore the universe as one of the top ten "most stunning" moments of Star Trek: The Next Generation.

In 2019, CBR ranked it as the third best holodeck-themed episode of all Star Trek franchise episodes up to that time.

In 2020, Screen Rant ranked Moriarity the ninth best holodeck character of the Star Trek franchise.

Releases
The episode was released as part of the Star Trek: The Next Generation season six DVD box set in the United States on December 3, 2002. A remastered HD version was released on Blu-ray optical disc, on June 24, 2014.