Wind a coil into a donut and the magnetic field is trapped inside — strong within the tube, exactly zero everywhere outside. That confinement is why a tokamak is a donut: it is a magnetic bottle for a star. Slide the current (or tap) and watch the field fill the ring and nowhere else.
A toroidal solenoid by Ampère's law. Take a circular loop of radius ρ concentric with the axis: only inside the winding does it enclose current, so B = μ₀·N·I/(2π·ρ) for R−a < ρ < R+a and EXACTLY ZERO outside the torus (the enclosed current is zero there) — the field is confined to the donut. Inside it falls as 1/ρ, stronger on the inner wall than the outer. This is the tokamak principle: a magnetic bottle with no ends for a plasma to leak from. The field profile B(ρ) is computed live. A fail-loud self-check throws unless B is zero outside the tube and falls as 1/ρ inside.
An idealised, tightly-wound continuous toroid (a real coil has discrete windings and a small poloidal leakage; a tokamak adds a poloidal field for stability). The Ampère 1/ρ profile and the zero-outside confinement are exact.