Usually the sulfur molecule contain 8 sulfur atoms.
Octasulfur is just one of few different allotropic forms of sulfur. It happens to be the most stable form at room temperature, but different conditions favor different forms. Thus, for instance, sulfur vapor usually contains S,S2,S4,S6,S8S,SX2,SX4,SX6,SX8, and the higher the temperature, the lower is the amount of S8SX8 molecules since they break up into smaller allotropes of sulfur.
So, while two sulfur atoms can share a pair of electrons by forming a diatomic disulfurmolecule with a double bond, so can also eight atoms, but by forming a puckered ring structure with few single bonds. Then it is basically the question of thermodynamic and kinetic stability, which form would dominate others at some particular conditions.