With a bit of luck it might just be external and your gearbox is fine.
If its not fully engaging the gear, it can jump out.
Check (or get someone to check) the coupling/linkage is not worn or has not come loose on the selector shaft of the gearbox and that the gear shifter on the cab floor is also correctly adjusted.