Based on the Mishna (Shabbat 16:8), the Shulhan Aruch (O.H. 276:1) rules that a Jew may not benefit from a light that was lit by a non-Jew on Shabbat, even if it was done on behalf of another Jew. This precept is a Rabbinic injunction and applies not only to lighting but, generally speaking, all the forbidden labors of Shabbat. In the context of this discussion, benefit refers to something that is absolute, not simply an improvement of a current state. For example, if one is sitting in the dark on Shabbat and a non-Jew turns on the light, one may not benefit from such an act. However, if one was in a room that had dim light and the non-Jew simply increased the intensity or amount of light, one may derive benefit. It should be noted that even in the latter case, one may not ask a non-Jew to perform this act. The Rama (ibid.) adds that if a non-Jew turned on the light for a Jew, even though it is forbidden to benefit from this, the Sages did not mandate that one leave one’s home just so as not to benefit from the light. One may benefit from the light of a non-Jew if it was lit for the non-Jew or if it was lit on behalf of an ill Jew, even if the illness is not life-threatening. Rabbi Yehuda Ayash (Mate Yehuda) adds that one may benefit from the light that was lit for a child that is in the dark.
The Shulhan Aruch (ibid:2) goes on to say that it is also permissible for a Jew to benefit from the lighting of a non-Jew if the majority of those present are non-Jews. However, if half of those present were Jews (and certainly if they were the majority), and half were non-Jews it is forbidden for the Jews to benefit from the light.
One practical application of these laws is sharing an elevator with a non-Jew on Shabbat (the nuances and propriety of using an elevator on Shabbat will be discussed elsewhere). If asked by a non-Jew to which floor one is going, one may not respond since this would constitute benefitting from the act of a non-Jew. Rather, it is preferable to get off on the same floor as the non-Jew and figure out a way to get to one’s floor, such as the stairs. It goes without saying that one should not do this if it will cause suspicion on the part of the non-Jews. If one happens to be going to the same floor as the non-Jew, then the act of pressing the floor is done for both parties. In such a case, the Rashba rules that this too would be forbidden. On the other hand, the Biur Halacha (§ 276, “Ve’im Yesh Hochacha”) rules that as long as the non-Jew is doing it for him/herself as well, then the Jew would be able to benefit.
Summary: A Jew may not benefit from a Melacha that was done by a non-Jew on Shabbat. One may benefit if the act was done specifically for a non-Jew, or if it was done for a Jew who is ill.