This is, of course, something that no one has managed to do effectively. No country has managed to prevent the flow of illegal drugs across its borders. That said, there are at least two things that might be done.
First, we could reduce the demand for these illegal drugs. In an extreme policy, we could legalize the drugs, allowing them to be made by reputable, non-criminal producers. This would drastically reduce demand for illegal drugs. Alternatively, we could work harder to prevent people from becoming addicted. We could provide more drug treatment programs. If demand were reduced, the flow of illegal drugs would be reduced.
Second, we could combat the supply of the drugs through economic means. If people in the countries where the drugs originate had better options for how to make a living, they would be less likely to engage in producing illegal drugs. Therefore, it might be a good idea to promote economic development in the countries where the drugs come from.
In these ways, we could reduce the flow of illegal drugs in ways that might be more humane than the current “war on drugs” model.