There is substantially more trade within national borders than across borders. An important explanation for this fact is the weak enforcement of international contracts. We develop a model in which agents build reputations to overcome this institutional failure. The model describes the interplay between institutional quality, reputations and the dynamics of international trade. It also rationalizes several empirical regularities. We find that history matters for trade volumes, but that its effects vary with the institutional setting of the country. The same is true for the efficacy of trade liberalization programs. Moreover, while stricter enforcement of contracts enhances trade in the short run, it makes it harder for individual traders to develop good reputations. We show that this indirect negative effect may produce an "institutional trap": for sufficiently low initial levels of contract enforcement, a small tightening in enforcement reduces future trade flows. We find also that search frictions aggravate the problems created by weak enforceability of contracts, even if they impose no direct cost on agents, but that trade liberalization can mitigate these negative effects.