They do so because someone outside the country can produce something more efficiently than they can inside the country. Example: You can grow rice more efficiently outside the US than in the US, so we import a lot of rice to countries who might wish to buy software from the US because we write better software than they do. Both parties are better off because of the trade. This doesn't mean that the US won;t grow ANY rice or that Indonesia won't write any software, but all trade is relative.