If two entities from different countries A, B sign a contract, does the contract follow:
- law of the country, where the contract is signed
- law of a country of choice from A and B
- international contract law
The question you have posed is called a "choice of law" question. All three of the possibilities that you suggest (and more) are the right answer in some circumstances.
Choice of law by agreement
Unless the choice of law for some reason violates public policy (e.g. because the law of country A does not make something illegal, but the law of country B where the contract is to be performed does make something illegal) a choice of law made within a clause an international contract that has any connection to the parties or the contract will be honored (which is your possibility number 2).
General choice of law rules when there isn't a contractual choice of law
Before you have a contract, the issues of contract formation, and other contract law issues to the extent that there is no choice of law clause in the contract that does not violate public policy, could be governed by the law of the place where the contract is signed, by the law of A or B since they are parties to the contract, or, for example, by the law of the place where the contract is to be performed.
The leading choice of law rule in the United States in these circumstances is to apply the law of the one of those options with the most significant relationship to the contract, which is a test that is just as fuzzy and indeterminate and open to case by case interpretation as it seems.
Also, there isn't necessarily only one set of laws that will apply to the contract. The legal term for applying different laws to different issues that arise in the same legal case is called dépeçage.
For example, the law of the place where the contract is signed might govern the issue of contract formation, while the law of the place where the contract is to be performed might govern performance of the contract.
Consumer protection laws are often applied to contracts with consumers based upon the place where the consumer is domiciled or is located when the contract is entered into by the parties.
It isn't unusual for a contract to be subject to the law of more than one place on issues other than issues of contract formation, and other than on issues of contract interpretation. But, any given legal issue related to a contract is ordinarily subject to only a single jurisdictions laws (unless it is a public policy regulation).
Unless anyone argues in court that the law from another place should apply to an issue and that law is different from the legal rule in the place where the court is located, in a court case, a court will apply the law of the place where the court is located (called the "law of the forum."
Exceptions to the general rule
There are some international treaties which create exceptions to the general rule and instead provide that a contract will be governed by law established in an international treaty (which is your possibility three). There are at least two such treaties to which the United States is a party which are notable and come up with some frequency.
One of them is the CISG, which is the Convention on the International Sale of Goods that governs international contracts for the sale of goods that are not expressly excepted from the treaty (mostly business to business sales of goods), when both the seller and the buyer are associated with a country that is a party to the treaty.
Another is the New York Convention a.k.a. the "Convention on the Recognition and Enforcement of Foreign Arbitral Awards" a.k.a. the "New York Arbitration Convention" which governs governs contracts with arbitration clauses in them that involve parties from different countries that are both parties to the Convention.
In addition to these treaty provisions, some international contracts are governed in the United States by admiralty law, rather than by the federal and state laws that would otherwise apply to these contracts. Obviously, the affected contracts are contracts with a maritime dimension, either in international waters or in the "navigable waters of the United States."
I am certain that this list of exceptions governed by special laws is not complete (e.g. certain international treaties apply to contracts involving international airline travel), but the question doesn't identify anything about the contracts that make them stand out.
Very often in internation contracts there will be a choice of law clause, which will specifically address this issue.
If no choice of law clause is part of the contract (very unlikely) then it seems according to at least some sources in this case https://www.trans-lex.org/971000/_/law-applicable-to-international-contracts/
(a) A contract shall be governed by the law chosen by the parties. The choice shall be made expressly or clearly demonstrated by the terms of the contract or the circumstances of the case. By their choice the parties can select the law applicable to the whole or to only part of the contract. The parties may at any time agree to subject the contract to a law other than that which previously governed it.
(b) Absent a choice of law by the parties, a contract is governed by the law with which the contract is most closely connected ("centre of gravity test"; "engster Zusammenhang"; "liens les plus étroits").
(c) Contracts are most closely connected with the law of the country where the party required to effect the characteristic performance has its habitual residence, seat or place of business.
(d) Where it is clear from all the circumstances of the case that the contract is manifestly more closely connected with a country other than that indicated in paragraphs (b) or (c), the law of that other country shall apply.
(e) The law applicable to a contract by virtue of this Principle shall govern in particular:
iii) the consequences of a total or partial breach of obligations, including the assessment of damages in so far as it is governed by rules of law;
iv) the various ways of extinguishing obligations, and prescription and limitation of actions;
v) the consequences of nullity of the contract.