Could you put a machine (that wasn't powered by TNT or something equally crazy) into a space ship for protection from cosmic rays? Is that something people are looking into?
I don't have a source on hand but I have read some study that theorized a very powerful electromagnet in a mars-sun lagrange point could be used to create a magnetic field to shield mars from cosmic radiation in a similar way to earth's magnetosphere. I seem to remember the power needed being (obviously) very large but surprisingly not many orders of magnitude out of plausibility. For a much smaller entity than a planet (spaceship) it may be possible with a low enough power consumption to make it possible. I would imagine there would be many many engineering concerns with having such a high powered magnet in your spaceship though.