Can a priest validly celebrate a mass without anybody else present? Say that a priest for whatever reason wanted to do a mass by himself. He does all the parts of the liturgy, including the consecration of the Eucharist. The only thing is, he’s completely alone; nobody else is present. Would this mass be valid? Or does there have to be other people (by which I mean “participants”, usually lay people)?
May a priest validly celebrate a mass without anybody else present?

The short answer is: Yes.


  The General Instruction of the Roman Missal (GIRM) says, “Mass should not be celebrated without a minister or at least one of the faithful, except for a just and reasonable cause. In this case, the greetings, the introductory or explanatory remarks, and the blessing at the end of the Mass are omitted” (254).
  
  There is a constant metaphysical sense of our Catholic worship. Thinking with the Church there are times when a priest, without a congregation and without a server (to represent the faithful) may offer Mass by himself. The Church teaches that every effort ought to be made to have a server make the responses and to keep the priest honest in following the rubrics, but there may be times when the priests needs to offer Mass only in the presence of the Angels and Saints. Remember, we do not hold that a priest owns the Mass for himself. Yet, we are also taught that a priest does not need a lay person for the proper celebration of the Mass. Traveling causes these tensions, or there is a need to offer Mass for a particular intention that needs immediate Divine assistance, e.g., the sick and dying, a special circumstance in society or church. A priest in a nursing home may offer Mass without a congregation. Bishops with a rare day free of public ceremonials may offer Mass privately from time to time. Jesuits, many monks and hermits frequently offer Mass in alone. All this seems to be contextualized by the Code of Canon Law that says, “This is true with respect to the liturgies celebrated by religious communities” (678,1). Ultimately, it is held by the Catholic Church that it is both licit and valid for a priest to offer Mass alone. - Private and Public Catholic Mass?


The Extraordinary Form of the Mass (EF) is less flexible in this matter, but it is not absolutely forbidden either: 


  Canon law stipulates that a priest should not celebrate Mass alone, but have at least a server or a lay person making the responses, but a solitary celebration is not to be forbidden absolutely if there is a good reason. A motive of piety and love of the daily Mass is generally thought to be adequate as a good reason. It frequently happens that a priest is in good standing with his Church and Bishop (not sanctioned or suspended, etc.) but has no pastoral ministry, for example for reason of having a teaching post or doing further theological studies at a university.
  
  In times gone by, the Church was much stricter about this rule, and Blessed Charles de Foucault in his hermitage in Algeria was deprived of the Sacraments for several years. He applied for and obtained a special indult from the Holy See to say Mass entirely alone – since there were no other Christians anywhere at all nearby, and the local Muslims were hardly to be expected to come and assist at Mass (seeing as he never converted any of them). - Mass without a congregation


Other sources:


  Celebrating Mass Alone
  
  When Celebrating Mass Alone
  
  III. Mass at Which only One Minister Participates (GIRM #254)
  
  Canon of Canon Law 906