They were trying to get to their parents. In the final days of WWII, the Pacific Ocean and the islands by the Philippines were devastated from bombings and all the fighting. Caught in the armies crossfire were civilians and others native to the islands. Patrick and Teddy had been having bad luck ever since the Japanese invaded the Philippines. Their parents, in an attempt to save them, sent them away to another island, not knowing the two boys would end up in grave danger there as well.
Once the Japanese were driven off the island of Guam, Patrick has the idea if he can only get back to the Philippines, he can find their parents and be re-united with them after four long years. However, the only way for two young boys to get there is by becoming stowaways. It turns out they pick the wrong ship. With the help of a marine named Benny, they are smuggled aboard a ship called the U.S.S. Indianapolis.
This proves to be a fateful move however, since the Indy is torpedoed by a Japanese submarine and sinks in under 13 minutes. Benny, Patrick and Teddy make it into the water, but Benny is severely hurt in, and Teddy is basically no help. So Patrick must try to keep them alive even as the waters churn with sharks, ready to take them down, deep into the sea.
Into the Killing Seas by Michael Spradlin is a great historical fiction look at the sinking of this ship during WWII, and the worst encounter between humans and sharks ever recorded.