The density is actually lower than the sun in magnetic confinement fusion (MCF) devices because we can’t squeeze plasma together as hard as the sun’s mass can. Inertial confinement fusion (ICF) can squeeze harder than MCF devices, but has serious unaddressed engineering issues.
The trick is in higher temperature plasma. The sun fuses protium (lone protons). We don’t have the confinement necessary on Earth to do this, so we fuse deuterium (1p+1n) and tritium (1p+2n). This reaction is more energetically favorable and is achievable on Earth. Coupled with giant microwave ovens and clever geometry and electromagnetic tricks, we can make plasmas much hotter (faster moving particles) than the sun can.
Once a plasma is fusing, it emits a lot of heat (alpha heating and fast neutrons). A plasma that requires no external heating (no microwave ovens) is said to be “ignited”. We don’t necessarily need or want ignition to have a successful reactor, but it’s a cool thought.
The major trouble with fusion reactors is keeping particles in the bottle long enough to fuse. Since they’re leaving anyway they have to go somewhere. You can tune vessel geometry and magnetic fields to have designated strike points where most of the plasma will exit confinement. These are called divertors. Run some coolant through your divertors and you have a heat source that can boil water and spin a turbine.
Here my knowledge gets shaky because I know that the fastest particles coming out of a D+T reaction are neutrons (they weigh much less than an alpha particle). Since neutrons are electrically neutral I think they are much less likely to become thermalized (they are not likely to bump into another particle on their way out). I’m not sure how neutron thermalization happens in reactor simulations, but I’m under the impression that it does.