Apartments: yes. Land: generally no.
The Land (Restrictions on Alienation) Act restricts foreigners from acquiring freehold land, but condominium apartments are exempt. Since the 2018 amendment, a foreign national can buy a condominium unit on any floor of the building.
Pay through an inward remittance
The full purchase price has to be paid upfront through an inward foreign remittance into Sri Lanka before the deed is executed. Keep the bank documentation — you will need it to prove the funds came from abroad.
Due diligence
Hire your own Sri Lankan lawyer. They should confirm the condominium plan is registered, review the developer's title, check for mortgages, obtain the Certificate of Conformity for completed buildings and confirm there are no service-charge arrears on the unit.
Costs to expect
Expect stamp duty, notary fees and registration fees on top of the price. Ask your notary for current rates when you agree the deal, as they change with national budgets.