I had a thought experiment.
Suppose you fill a conducting metal box with ions or other charged particles. Accelerating charges generate electromagnetic field, which induces a current in the presence of a conductor. Because the ions bump into the box walls all the time, get decelerated due to induction and then re-accelerated by other ions, this could effectively turn all the heat in the box into electricity. While the magnetic field in the box itself would cancel out and have no effect other than influencing other ions motion, near the wall the particles would have no other choice than to bump into the wall.
If the metal box conducts heat, this would turn heat from the outside slowly into electricity.
This seems to be violating the second law of thermodynamics, because you could turn the heat into electricity, use it nearby and turn the heat generated by the work into electricity again.
This seems to be wrong in some way but I don't know where my reasoning fails. What's the problem with the above thought experiment ?