score:1
No. You cannot apply for a U.S. visa inside the U.S. A U.S. visa is only for entering the U.S., and can only be applied for while outside the U.S.
Even if you had a visa, it does not mean "for sure that you will be able to come back". A visa just permits you to apply for admission. It is always possible to be denied entry on a nonimmigrant visa.
Upvote:2
In theory, you could start the application a few days before going home, so you can go to your appointment as soon as you arrive in your home country. However, this may not work:
I would still get started before I leave (you need to do things like get an I20 signature and get documents from your school anyway), and fill out as much of the paperwork as I can. But don't count on it saving you more than a day or two from a process that may take several weeks.
Upvote:3
Most F1 visas for the US last for 1 year more than the average degree duration. In my case, the visa was stamped for 5 years for a 4 year bachelor's degree.
If your visa has not expired then you need to make sure to get a travel signature on your I-20 from your school's Department of International Education which is valid for one year and allows multiple entries and exits from the United States. If you ensure the same, you are free to travel anywhere you like and enter and exit the United States up to your free will until that travel signature expires.
Travel Signature on an I-20 is a signature that is issued by an international student advisor, which acknowledges that you are a full-time student in F-1 status and that you are maintaining your status at your University. The signature appears on page 3 of the I-20.
If your visa has expired or is due to expire before you complete your education, then you must contact your Department of International Education and request for a visa extension with a US embassy.
You can choose a US embassy in wherever location most comfortable to you as there will obviously not be any inside the United States. I would suggest choosing your home country though. Unfortunately, I don't think there is a way for you to confirm in any way whether you can return back to the US but you can certainly start filling out your application and get an appointment date such that it meshes well with your travel back home.
Also, since you visa has already expired you are legally obligated to go back.