“It’s becoming less and less sexy to be going to the United States,” said Tim Delisle, 26, a founder of the start-up Datalogue, which uses artificial intelligence to prepare and synthesize data for other businesses. He added that skilled foreign workers crave the greater stability that he said immigrants have in Canada compared with the United States.

While much attention has been paid to President Trump’s policies cracking down on illegal immigration, the administration has also moved to restrict legal immigration, especially in the tech industry, which draws many workers from abroad. In April, Mr. Trump introduced an executive order, Buy American and Hire American, which included requests to reform a visa program known as H-1B as a way to benefit American workers.

The program awards 85,000 temporary visas annually to highly skilled foreign workers in what are deemed “specialty” occupations through a lottery. Between application and legal fees, the process of applying for one H-1B visa can cost a company up to $6,000, lawyers say, and can take months; it is also as uncertain as roulette, with hundreds of thousands of applicants for the spots.