A solenoid by constuction has two magnetic poles at the edges when current is flowing through its widings so flux leaks out from solenoid.
One can think toroid as a solenoid that has been curved and joined, so no poles are open.Hence Magnetic field lines can be entirely confined within the core of a toroid.