I made a bed rail out of copper pipe for my goucho bunk but you could use PVC pipe instead and slide it under the cushions (I assume). Copper pipe is thinner, so it would have less of a bump under the cushion. I had to use copper to fit inside square rail supports that I had to add under the bunk. You could add as many vertical and horizontal rails, as closely spaced, as you like. If the under cushion legs were screwed on then it would be easier to store it out of the way.
The bathroom wall provides a built in bed rail for about a quarter of the bed so a rail doesn't have to be too long. I don't think you would want to totally rail off the entire width as there would be no way to climb into bed.
This link provides details.
Escape Trailer Bunk Bed Rail - Fiberglass RV