All perfect praise be to Allah the Lord of the Worlds. May His peace and blessings be upon Prophet Mohammad and upon all his family and companions.
The general rule is to validate sales transactions that people have adopted as custom, provided they are free from Gharar (excessive uncertainty) and Jahālah (ignorance of the product) that lead to dispute. The Messenger of Allah (peace and blessings be upon him) said: "What the Muslims deem to be good is good in the sight of Allah" (Reported by Ahmad). Conversely, transactions built upon ignorance and Gharar are prohibited by Shariah, as they constitute consuming people's wealth unjustly. Allah the Exalted says {what means}: "O you who have believed, do not consume one another's wealth unjustly" [An-Nisā’/29].
The sale of "closed boxes" falls into two categories, and the ruling differs accordingly:
Case 1: Total Ignorance of Content
When the contents of the boxes are unknown in terms of both type (Jins) and quantity (‘Adad). This case is prohibited (Ḥarām) because it involves excessive ignorance and Gharar.
Case 2: Known Types but Unseen at Purchase
When the boxes contain products known to the buyer but not seen—and it has become customary for people to trade them this way. The majority of jurists originally view this as impermissible. However, the Hanafi masters permit it. Imam Muhammad ibn al-Hasan al-Shaybani (may Allah have mercy on him) stated: "What do you think of a man who goes to another who has a bale of clothes, and the owner says: 'I do not know how many garments are inside, and if I open it and count them, it will damage the bale, and the manifest (Barnāmaj) is lost.' Is it not appropriate that the sale of this should be permissible without opening and counting? This is permissible... Do you not see that if a man brings a load of walnuts to the people of Medina, and they are sold by count, is it not permissible to sell them by estimation (Majāzafah) until they are counted? If a man has many eggs and sells them by estimation, is that not permissible? ... If you say this is permissible, then you must permit the former, for there is no difference... We do not doubt that you permit selling walnuts and eggs by estimation, so measure [the ruling on] cloaks, boots, and caps against these things... There is no sale more permissible than the sale of estimation which does not require measure, weight, or count." [Reference: Al-Ḥujjah ‘alā Ahl al-Madīnah, Vol.2/P.731].
In conclusion, the sale of closed boxes is permissible if they contain products whose general nature is known to the buyer, if this aligns with local commercial custom (‘Urf), and if the uncertainty that leads to dispute is negated. However, selling closed boxes where the category or nature of the products is entirely unknown is impermissible due to the presence of Gharar and Jahālah. And Allah the Exalted knows best.