 Such a field can be created in a solenoid, a cylinder with magnets wrapped around the outside.The combined fields of the magnets create a set of parallel magnetic lines running down the length of the cylinder.This arrangement prevents the particles from moving sideways to the wall of the cylinder, but it does not prevent them from running out the end.