An effective way is to roll a towel. Make it into a long cylinder and place it along the outer edge of the bed. For more safety, you can slip it under the sheet with some extra effort. That way it cannot easily be pushed off. You can easily get additional towels for this on the cruise ship if you don't already have enough, so you wont have to pack extra items.
Amazon has many portable bed rails for kids that come in many sizes and shapes (large, small, long, short, etc.) and they're affordable. They are easily installed on almost any bed/bunk with a mattress.
Check the bunk size, order one that fits it. Do not take any risk and ruin the trip.
Speak to the steward when you arrive. It is unlikely to be the first time this problem has arisen, and ships usually have some sort of straps available for passengers who are nervous (reasonably or otherwise) about falling out of bed in a storm. Asking an expert (who can expect a larger tip) is much better than trying to solve it yourself without knowing the details of the cabin, or even asking here.