This idiom comes from Sun Tzu's Art of War (
孙子兵法). Sun Tzu said that soldiers from the rival states of Wu and Yue, if on the same boat in a storm, would help each other just as left and right hands do. The English equivalent 'in the same boat' captures the same idea.