The origin of idioms is always problematic. To draw a line is the sand, meaning this far and no farther, probably comes from a story out of the Roman Empire.
A Syrian king was intent on waging war against Egypt, then a Roman protectorate. A Roman envoy, Gaius Popillius Laenas, confronted the king and told him to withdraw or face war with Rome. When the king hesitated, Laenas drew a line around the king and told him to order a retreat before stepping out of the circle. The king withdrew.
There is another story that line in the sand refers to William Travis at the Alamo drawing a line with his sword and asked those willing to stay and defend the Alamo to step across. However, that is unlikely as Travis's act does not fit the definition of the idiom.
A line in the sand is also an important part of the rules to the Over The Line tournament being played in San Diego this weekend.