Stanley Yelnats IV (Shia LaBeouf) is a good-hearted teenager born to a luckless family that has been cursed for generations. The luckiest of the Yelnats ancestors, Stanley Yelnats I (Allan Kolman), lost his fortune when outlaw "Kissin' Kate" Barlow stole his treasure chest. The Yelnatses blame their Latvian ancestor Elya Yelnats (Damien Luvara), who was cursed after breaking a promise to carry Madame Zeroni (Eartha Kitt) up a mountain.
Stanley is wrongfully arrested and tried for stealing a pair of baseball shoes that Clyde "Sweet feet" Livingston (Rick Fox), a famous baseball player, had donated to charity. Stanley is sent to Camp Green Lake, a juvenile work camp, for his alleged crime. He arrives to find that the "camp" is a dried-up lake run by the corrupt Warden Walker (Sigourney Weaver), her assistant Mr. Sir (Jon Voight), and camp counselor Dr. Pendanski (Tim Blake Nelson). Each day, the detainees must dig a hole 5 ft deep and 5 ft in diameter to "build character," despite the danger of the desert sun, rattlesnakes, and yellow-spotted lizards, which can kill with a single bite. The children are told that if they find anything interesting, they may earn a day off. The inmates, known by their nicknames, include Zero (who refuses to speak to anyone, but likes to dig holes), Armpit, Zig-Zag, Squid, X-Ray and Magnet. Stanley is slowly accepted into the group and is given the name "Caveman." He soon creates a friendship with Zero (Khleo Thomas), whose real name is Hector Zeroni, while teaching him to read.
A flashback shows how the men of the Yelnats family suffer under a bad luck curse that affects all aspects of their lives. Stanley II tells Stanley IV the story of how it all started with his great-great grandfather Elya Yelnats in Latvia. Elya worked for Morris Menke (Ravil Isyanov), shoveling manure out of his barn. Elya thought Menke's daughter Myra (Sanya Mateyas) was very beautiful. He goes to a fortune teller, Madame Zeroni, for advice about his destiny. Madame Zeroni recommends that he go to America, where her son has gone, and that his future should be there, instead of with Myra, who is empty-headed. Elya asks Menke for permission to marry his daughter, but Menke says that Igor (Ken Davitian), who is eating with him, has offered her his fattest pig (Igor is fat, too). To prove her point about Myra, Madame Zeroni advises Elya to take a young pig and carry it up the mountain every day so that as the pig grows, he will get stronger. Further, he should sing the pig a certain song when it drinks water from the stream. She tells him that after the pig is full grown and he gives it to Menke, Elya must carry her up the mountain and sing while she drinks, so that she will regain her strength. She gives him a warning, though, that if he forgets to perform that last task, she will curse him and his generations to eternity. Elya gives the pig to Menke, and Menke allows his daughter to choose who she wants to marry. She is indecisive. In anger, Elya tells her to go ahead and marry Igor. He takes Madame Zeroni's advice and heads to America, but forgets to carry her up the mountain as she ordered him to do, if he wants to be spared the curse. He realizes that he has just made the biggest mistake of his life.
Another flashback, which reveals how the modern story comes together, relates the history of Camp Green Lake. The town was once a thriving lake town with plenty of water and life. Miss Katherine (Patricia Arquette), the schoolteacher, is accosted by a rich landowner, Warden Walker's ancestor Trout Walker (Scott Plank). He proposes to her, but she rejects him. Miss Katherine is in love with the onion seller Sam (Dulé Hill), an African American who helps repair her schoolhouse in exchange for her renowned spiced peaches. Among other things, Sam claims that regularly consuming onions and 'onion juice' will keep the local yellow-spotted lizards away. When Sam kisses Miss Katherine, the townspeople burn the school. Sam attempts to escape in his boat, the Mary Lou, but Trout kills Sam. In retaliation, Kate kills the sheriff (Eric Pierpoint), who refused to help Sam. She leaves a lipstick kiss on his forehead, beginning her life as the outlaw "Kissin' Kate," who kisses the men she kills.
Back in the present, Stanley finds a tube of lipstick that belonged to Kissin' Kate Barlow (Miss Katherine), but he gives it to X-ray because X-ray hasn't had a day off in six months. X-ray gets an entire day off for the tube. Then Armpit tries to pass off a stove knob as something he dug up, but the Warden knows better, and Armpit's joke costs him a week of no shower privileges.
After Dr. Pendanski insults Hector, he retaliates by hitting him with his shovel and runs away. After some deliberation, Stanley sets out to help Hector and finds him taking shelter under the remains of Sam's boat, the Mary Lou. Zero, now stranded in the desert, offers Stanley the last jar of "sploosh" (an old jar of Miss Katherine's spiced peaches which had been left on the boat). Stanley, knowing they can't survive in the desert for much longer, heads over to a mountain called God's Thumb.
Meanwhile, Walker decides to presume Hector is dead and deletes his files. Stanley carries Hector up the mountain where they find a field of onions and a source of water, helping them regain strength for several days. Unknowingly, Stanley breaks the family curse because Hector Zeroni happens to be a descendant of Madame Zeroni. When he carries Hector to the top of the mountain, sings to him, and lets him drink from the stream that runs uphill, he fulfills the promise made by Elya centuries earlier. After Hector wakes up, he reveals he is the reason Stanley was sent to Camp Green Lake. Hector tells Stanley he had been homeless and had been at the shelter where many things (including Sweetfeet's shoes) had been donated. Because he did not know the shoes were famous, he took the shoes and walked off with them. He then heard sirens coming; thinking they were after him, Hector took off the shoes and tossed them over the bridge, where they fell on Stanley's head. This is how Stanley was caught with the shoes and sent to Camp Green Lake. Stanley thinks it is destiny that they met.
In a flashback Kate Barlow, now older, is found in the middle of the now dried-up lake by a pair of husband-and-wife bounty hunters: one of her former students along with Trout Walker (whom the student has married). They mention that the lake dried up because it hasn't rained since Sam died. They order Kate to hand over the Yelnats treasure, but she tells them that they "can dig for a hundred years, and will never find it." Kate allows herself to be bitten by a yellow-spotted lizard on the arm; she suffers for a while and soon dies.
As Stanley breaks his family curse, his father finally finds the solution to an odor-eliminating mixture that he has been trying all his life to create -- the addition of peaches and onions. Stanley and Zero decide to go back to Camp Green Lake to investigate the hole in which Stanley found the tube of lipstick, feeling lucky all of a sudden. They dig deeper into the hole and uncover a chest. Warden Walker and Mr. Sir discover them and attempt to take the chest away from Stanley and Zero until they notice that yellow-spotted lizards have climbed onto the boys.
When the group is discovered the next morning by the assistant attorney general (Ray Baker) and Stanley's lawyer Carla Morengo (Roma Maffia), Walker attempts to explain that the chest is hers, at which point Stanley jumps out of the hole to confront her with Hector behind him. They are still alive due to the fact that yellow-spotted lizards are averse to the onions they had been eating. Hector reveals that "Stanley Yelnats" is written on the front of the chest.
Back at camp, the lawyer finds out that there are no files on Hector. One of the cops notices that Mr. Sir (who was revealed to be Marion Sevillo) has a gun, which is a violation of his parole. When Warden Walker states that she had no knowledge of this, Mr. Sir blurts that Dr. Pedanski isn't a real therapist. The assistant attorney general then declares Camp Greenlake under his jurisdiction as Marion, Warden Walker, and Dr. Pendanski are arrested. As Stanley is beginning to leave, rain falls on Camp Green Lake. Walker, Marion, and Dr. Pendanski are shocked -- it hasn't rained at Green Lake in years. Walker asks Stanley to show her inside the chest, but Stanley refuses. Stanley then drives home with Hector.
The Yelnats family claims ownership of the chest and its contents. Stanley decides that half the money should go to Hector and Hector uses some of his share to hire private detectives to find his mother (Shirley Butler).
Camp Green Lake is closed and all its juvenile inmates are sent home. Later, it reopens as a girl scout camp. At the end, an advertisement appears on TV for the odor-eliminating mixture Sploosh; the celebrity endorser is Clyde "Sweet feet" Livingston. Stanley, Clyde, and others watch.