The first step is to develop reasonable policies for legitimate foreign workers. Anywhere you have a border with the kind of wealth disparity that exists between the US and Mexico, you're going to have a massive draw for the eager labor on one side to meet up with the paying customers on the other.
I had a fascinating experience at the Alamo a couple of years ago. The tour guide gave a brief history of the region and the situations that led to the famous battle there. He explained how, after Mexico won its independence from Spain, it was eager to advance itself and develop the wilderness of the region that was to become Texas. They began an aggressive campaign to lure settlers to the region. They offered grants of cash and property to anyone willing to develop the land. The offers were extended to anyone willing to work, regardless of nationality.
Shortly thereafter, however, a conservative backlash in Mexico City marked a radical reversal of that policy, and the offers halted. In some cases they were reversed. It seems the conservatives were worried about all the foreigners (mostly US Americans) 'invading' their land and watering down the Latin-American/Spanish culture. They closed the borders and did their best to keep people out.
But, as the tour guide pointed out, when there is a wealth of opportunity on one side of a border, and eager people yearning for that opportunity on the other, there's very little hope of keeping them out. And they couldn't. In the end, their draconian efforts to do that backfired on them, and they lost Texas.
The point is, pretending we can keep hungry people away from the work that will feed them is delusional. And I see no reason why we should.
The best way to keep the dangerous elements from crossing the border is to make sure that the vast bulk of immigrants who aren't dangerous can cross safely. When the legal channels are easier than hiking through the desert, legitimate immigrants and guest workers will gladly use them rather than supporting the pipeline of illegal immigration. Then we can focus on the remaining "illegals" vigorously, when their number will be reduced and we can be sure they are up to no good. As it is, we're treating all of them as a threat and we can't possibly deal with the volume.