Depends. If you are in most countries you can find a brokerage firm that allows you to buy US stocks. However, if you live in a country on the OFAC (Office of Foreign Assets Control) prohitbited list you won't be able to invest:
Currently, sanctioned countries include the Balkans, Belarus, Burma, Cote D'Ivoire (Ivory Coast), Cuba, Democratic Republic of Congo, Iran, Iraq, Liberia, North Korea, Sudan, Syria, and Zimbabwe. The list of sanctioned countries is updated periodically and is available here.