The onlyporoblem with attaching something permanent is when you want to raise that bed portion for when you are traveling and want to move around from the cab to the rest of the motorhome.
You can buy inexpensive bed safety rails at any Walmart, Target, etc. They just go under the mattress, but you could tack them to the end of the cabover sliding floor with some L brackets. Simple and inexpensive.
There are net and webbing solutions, require installing fasteners or hooks. These can be rigged to keep a child from climbing out, until clever enough to unhook it, which for my grandson would have been about 14 months. He is mechanically inclined with strong problem solving skills. But different kids are different.
First owner of my RV used wire shelving, stuck the short end under the mattress. This would work to prevent an accidental roll out, but easily climbed over. I still have the pieces in my garage.
When we had bunk beds as children, for some of us a 2 inch rail prevented rolling out, others needed a foot-high fence. I wake up feeling the edge of a bed, my 60+ little brother still ends up on the floor without waking.
Solution depends on what you are trying to accomplish, and the individual.
I took off one of the side rails from the house bunk bed and attached it to a 1 x 4 x 7. Easy to put on and take off. I've also heard about someone putting a water noodle under the bottom sheet to provide a reminder of where the edge is.
You can buy rails that are used on regular beds. Check wirh walmart or toys r us My hubby made them for our grandchildren, so you could check a woodworking shop.
In my mom and dad's camper when I was a kid, the overhang (bed) had a ladder. The ladder had two pegs on the side about 3-4 inches long. The pegs on the ladder fit into 2 holes drilled on the edge of the over hang bed, and when turned sideways, in place in the overhang looked like bars on a baby crib (only much wider). It worked very well, the wooden ladder was light enough, that even at 8 years old I could lift it out of the holes, set it on the side of the bed and use the ladder without help. My sisters slept on the bench-table-bed under the front window, and (as tempting as it was), I never clobbered them in the head setting the ladder in place when I slept up there. Maybe you could make something like that. (See my profile -link on the left- for a photo of that camper).