When you went onto your toe edge, were you doing a 50-50, sliding forwards, or sliding backwards?
When riding boxes or rails it's super important to keep the base of your board flat at all times. As soon as you get on edge, you will slide out.
So how do you keep your board flat on the rail?
Here's a few points to think about...
Commit. If you are scared, you won't commit, and you will likely slide out. If you are scared, start on a small feature where the consequences are low. Start small, get comfortable, then progress to something bigger.
Always stay perfectly balanced on your snowboard, with all your weight stacked over the board.
Your body should always be perpendicular to the rail. If the rail is on an angle, get your body perpendicular to the rail. If you are sliding forwards, get your weight forward. If you are sliding backwards, get your weight over your butt.
Edges. A big NO NO. Keep that board FLAT.
Let me know if you have any questions.