Just so we’re clear are you talking about literally falling asleep? If that’s the case you probably have narcolepsy.
If it’s a matter of your brain staying active enough to be able to engage, without getting frozen, a few things:
Limit morning caffeine. It’s an upper, and uppers crash down. The down part isn’t so useful for being alert
Limit the size of lunch
Avoid inflammatory foods at lunch
Get a little exercise
Use pomodoro timer to ensure you take a break before you need one
Hydrate well
On that last point: breaks are like pain meds: you should take one before the need for one becomes apparent. Keeping to that strict 25-5 schedule is great for keeping me close to peak in terms of my ability to do cognitive work.
For insomnia, the best thing for me is a 5-minute meditation session using a Muse 2 device (consumer neurofeedback training device, about $250 on Amazon). If I’m having recurring insomnia, a 5-minute session on the muse gives me about two weeks of insomnia relief.
Mostly though, I do indeed avoid desk jobs in favor of jobs that have at least some physical activity. My current job is about half desk, half physical work. And lots of face to face interaction too. Interacting with others keeps me energized.