When you buy a finished product made in Taiwan or Brazil, you purchase the factors of its production that went into making it. (See previous example with a pencil; the uncoordinated actions of thousands of people from diverse countries combine to make every single product and service we buy.) The Tawainese or Brazillian laborer cannot immigrate to the US and likely don't want to, but they provided a good or service that no one locally was able to provide at the same price (assuming you're rational and wanted to get the greatest amount of value for your dollar). Likewise, the goods and services that Americans produce are consumed abroad by people unable to find the same value at a lower price locally. (Wanting to get the most for their dollar seems to be a universal trait among humans.)
So, we Americans meet the need of others with our goods and services and others meet our needs, and everyone benefits. We're all humans, just living in different places. Restricting that flow of trade by limiting the amount of goods that can be sold from other countries (quotas) or artificially increasing the price of those goods or services (tariffs) restricts the ability to meet each others' needs. If you're legally restricted in where you can sell your product, then people who would have bought it have to settle for someone else's where they don't get as much bang for their buck and you're both worse off. Unrestricted trade alone allows us to find all the ways to create the greatest value for others.
Many economists are for open migration for the same reason. Some Taiwanese or Brazilians or Americans may not be able to send goods and services but they could do the job if they were physically present here-- think barbers, engineers, surgeons, farmhands, etc. So goes the logic, why restrict each others ability to physically provide that value? Free trade applies to right of residency as well. I may be willing to trade my spot in America for someone else's spot in Turkey. We're both humans, why not trade those spots the same way I might sell a book to a Turkish person or buy a book from them?
Our current President is both hostile to free trade and to immigration. But in the wake of the immigration protests this week, Josh Barro wrote a decent column this week that begs the question of how the Progressive Left can logically be hostile to trade but open to immigration-- it would seem to be a paradox at least. If Bernie Sanders blasts trade for "taking jobs from American workers" by allowing us to buy products and services from other locations, how is it any different when workers who compete for those exact same jobs abroad come into the country and do so here? There would seem to be no logical difference.
"(E)ventually, Democrats will need to be able to make a case that their preferred immigration policies serve the national interest. They're not yet positioned to do so." Other than altruism for refugees, Barro doesn't see a clear argument on the Democratic side for allowing in other workers who would compete directly with American workers, be unable to vote, and (at least initially) consume more government services than they would pay in taxes. Barro doesn't quite connect the dots to the trade and utility maximization logic above-- that's a shame. The understanding that trade makes both parties better off and more trade is better than less used to be much more bipartisan (see the US leadership in Bretton Woods, GATT, and the WTO) and, when not bipartisan, championed much more by Republicans. That's what makes Trump so problematic for the GOP. Barro is really just highlighting that the Democrats' weakness is their logical inconsistency. Trump is wrong both about the benefits of trade and immigration, but his logical consistency gives him an advantage.
So, the next time you buy a product that wasn't made here, ask yourself why. You'll likely find it's because you wanted the most bang for your buck. Likewise, the next time you criticize the President's executive orders on immigration, ask yourself why. If you find you don't want to give foreigners a chance to provide the greatest value for your dollar regardless whether the foreigner lives in Taiwan or in America, then you're with Trump. If you're sad you bought the foreign product but also sad Trump wants to keep the foreigner from coming in to make a similar product, then you've got a problem of logical inconsistency. Because immigration and trade are different types of the same activity.