How do non-metals form anions?
How else but by reduction?
The non-metal, which is formally to the right of the Periodic Table, has a high nuclear charge, and it tends to the be oxidizing, i.e. it accepts electrons.
Oxygen and fluorine gases are highly oxidizing gases, which can be appreciated by their position on the Periodic Table. They tend to accept electrons, and thus they form anions.
The halogen has been reduced to form, formally, a