In October 1997, 32 years into the future from the perspective of viewers in 1965, the United States is about to launch one of history's great adventures: humanity's colonization of deep space. The Jupiter 2, called Gemini 12 in the original pilot episode, a futuristic saucer-shaped spaceship, stands on its launch pad undergoing final preparations. Its mission is to take a single family on a five-and-a-half-year journey â updated from 98 years in the pilot episode â to a planet orbiting the nearby star Alpha Centauri. The pilot episode had referred to the planet itself as Alpha Centauri, which space probes reveal possesses ideal conditions for human life. The Robinson family, allegedly selected from among two million volunteers for this mission, consisted of Professor John Robinson, played by Guy Williams, his wife, Maureen, played by June Lockhart, their children, Judy (Marta Kristen), Penny (Angela Cartwright), and Will (Billy Mumy). They are accompanied by their pilot, U.S. Space Corps Major Donald West (Mark Goddard), who is trained to fly the ship when the time comes for the eventual landing. Initially the Robinsons and West will be in freezing tubes for the voyage with the tubes set to open when the spacecraft approached its destination. Unless there was a problem with the ship's navigation or guidance system during the voyage, West was only to take the controls during the final approach to and landing on the destination planet while the Robinsons were to strap themselves into contour couches on the lower deck for the landing.
Other nations are racing to colonize space, and they would stop at nothing, not even sabotage, to thwart the United States effort. It turns out that Dr. Zachary Smith (Jonathan Harris), Alpha Control's doctor, and later supposedly a psychologist and environmental control expert, is moonlighting as a foreign secret agent for one of those competing nations. After literally disposing of a guard who catches him onboard after hours, Smith reprograms the Jupiter 2's B-9 environmental control robot, voiced by Dick Tufeld, to destroy critical systems on the spaceship eight hours after launch. Smith, however, unintentionally traps himself aboard at launch and his extra weight throws the Jupiter 2 off course, causing it to encounter a meteor storm. This, plus the robot's Smith-programmed rampage causing the ship to prematurely engage its hyperdrive, causes the expedition to become hopelessly lost in the infinite depths of outer space.
The Robinsons are often placed in danger by Smith, whose self-centered actions and laziness endanger the family on many occasions. After the first half of the first season Smith's role assumes a less evil overtone although he continues to display many character defects. In "The Time Merchant" Smith shows he actually does care about the Robinsons after he travels back in time to the day of the Jupiter 2 launch with the hope of changing his fate by not boarding the ship and allowing the Robinsons start their mission as originally planned. However, once he learns that without his weight altering the ship's course the Jupiter 2 would be destroyed by an uncharted asteroid, he sacrifices his chance to stay on his beloved Earth by electing to re-board the ship, thus saving the lives of those he really does care about and continuing his position amongst them as a reluctant stowaway.
The fate of the Robinsons, Don West and Dr Smith is never resolved as the series unexpected cancellation leaves the Jupiter 2 and her crew literally on the junk-pile at the end of season three.

Question: Why was Smith on the ship?
Answer: he was trying to interfere with the ship's programming