They don't exactly (unless you mean under power). A fore-and-aft rigged sailboat can sail as close as about 25 degrees into the wind (although when one does this, the Course Over Ground (COG) usually drifts downwind some).
The principles in place are the same that apply to a wing on an airplane. The wind passing over the windward surface of a sail has a longer distance to cover than wind passing behind the sail (which would describe roughly a straight line). Therefore, a low pressure zone is created near the front or upwind surface of the sail, and force is applied in that direction. This effect is called "lift".
Chat with our AI personalities