A controller for a work machine, the controller comprising: a variable displacement hydraulic pump (17A, 17B) drivable by an engine; a plurality of actuators (9, 11) to which hydraulic oil is supplied from the hydraulic pump (17A, 17B); an input unit (22, 23) that receives an operation for inputting an actuation command relating to each of the actuators (9, 11); a storage unit that stores horsepower information in which an operation amount and an upper limit value of suction horsepower of the hydraulic pump (17A, 17B) are associated with each other, for each operation content identified by an actuator (9, 11) that is selected to be operated from the actuators (9, 11), and by a direction of the operation performed on this actuator (9, 11); an operation horsepower determination unit that determines the upper limit value of suction horsepower for each actuator (9, 11) by using the horsepower information stored in the storage unit, when an actuation command relating to at least one actuator (9, 11) is input by the input unit (22, 23); a high-level selection unit that selects the maximum upper limit value of suction horsepower out of the upper limit values of suction horsepower determined by the operation horsepower determination unit; and a displacement regulation unit (24A, 24B) that regulates a displacement of the hydraulic pump (17A, 17B) so as to obtain horsepower equal to or lower than the suction horsepower selected by the high-level selection unit, wherein the horsepower information relating to at least one operation content, out of the horsepower information stored in the storage unit, has a characteristic such that the upper limit value of suction horsepower varies in accordance with variations in operation amount of the input unit (22, 23). a variable displacement hydraulic pump (17A, 17B) drivable by an engine; a plurality of actuators (9, 11) to which hydraulic oil is supplied from the hydraulic pump (17A, 17B); an input unit (22, 23) that receives an operation for inputting an actuation command relating to each of the actuators (9, 11); a storage unit that stores horsepower information in which an operation amount and an upper limit value of suction horsepower of the hydraulic pump (17A, 17B) are associated with each other, for each operation content identified by an actuator (9, 11) that is selected to be operated from the actuators (9, 11), and by a direction of the operation performed on this actuator (9, 11); an operation horsepower determination unit that determines the upper limit value of suction horsepower for each actuator (9, 11) by using the horsepower information stored in the storage unit, when an actuation command relating to at least one actuator (9, 11) is input by the input unit (22, 23); a high-level selection unit that selects the maximum upper limit value of suction horsepower out of the upper limit values of suction horsepower determined by the operation horsepower determination unit; and a displacement regulation unit (24A, 24B) that regulates a displacement of the hydraulic pump (17A, 17B) so as to obtain horsepower equal to or lower than the suction horsepower selected by the high-level selection unit, wherein the horsepower information relating to at least one operation content, out of the horsepower information stored in the storage unit, has a characteristic such that the upper limit value of suction horsepower varies in accordance with variations in operation amount of the input unit (22, 23).