I am a French citizen with a B2 visa and I plan to stay for ~6 months in the US.
As I'll be hiking the Continental Divide Trail, I'd like to leave North America from Calgary Airport. I know that US and Canadian citizens have a simplified procedure to cross the border at Glacier National Park:
There is a US ranger station and customs post at Goat Haunt for south bound people into the US. It is a Class B Port of Call, which just means it is for US and Canadian citizens and permanent residents only. Northbound there is an RCMP post in Waterton townsite. Because of the twin park structure you do not seem to need to check in with the Mounties, as people take the boat down to Goat Haunt and walk back all the time. So, as a short answer I think you are ok just walking across.
But I can't find reliable sources for a non-US/Canadian citizen.
I'd prefer to cross the border at Glacier NP, because if I have enough time I'd like to continue hiking in Canada, taking the Great Divide Trail to get closer to Banff and Calgary.
I think I'd stay between up to 2 or 3 weeks in Canada, maybe less if I'm late on my hiking schedule.