In defining work, we focus on the effects that the system (e.g. an engine) has on its surroundings. Thus we define work as being positive when the system does work on the surroundings (energy leaves the system). If work is done on the system (energy added to the system), the work is negative.