The modern diesel engine is much more complicated than a purely mechanical diesel. It uses multiple sensors in the drivetrain to gather information that's sent to the engine computer, which controls all reactions to this information based on the driver's input. To squeeze more power out of the Cummins, Duramax, and Power Stroke engines, the aftermarket alters these electronic communications to maximize the horsepower and torque of the stock engines. There's plenty of easy power to be gained because the engines are built strong enough to handle much more torque than the factory settings, warranty, and emissions laws allow.

Programmers and boxes offer various levels of control-from a simple multiposition switch or LED display to touchscreen controls-and even the ability to hack into the factory engine and transmission computers.
Stock Engine Computer
It's true, the factory computer settings offer very conservative power levels because the OEM engineers are under many constraints that don't apply to aftermarket companies. In addition to building power, the programming inside the electronic control unit (ECU) must take several other things into account so your truck will idle smoothly, never smoke (even at wide-open throttle), and get good mpg numbers.
That's not easy, so power is sacrificed at the factory so every truck will work just as the engineers expect every time you turn the key for more than 100,000 miles. That's why multiple sensors in the drivetrain are used to constantly feed information to the ECU, which decides how to react and stay within the manufacturer specifications. Here are some of the main readings that are used by your truck's computer:
Airflow
Diesel engines don't use an air throttle (except for the new EGR-equipped engines), so the ECU uses a manifold absolute pressure (MAP) sensor-and in some cases, a mass airflow sensor (MAF)-to determine engine load by measuring the density, rate, and mass of air flowing into the intake manifold at a particular rpm. This tells the computer how much fuel can be injected for an air/fuel ratio that will lead to the preferred type of combustion. A perfect combination where all the oxygen and fuel will be burned is called a stoichiometric mix, but the fueling used to achieve this greenhouse- and mpg-friendly type of combustion does not create as much power as a more fuel-rich mixture would inside the same engine.

Fueling
Since the factory computer settings are concerned, first and foremost, with fuel-system durability and achieving a clean-burning combustion, the fueling system is not forced to perform up to its full potential. Much like purely mechanical injection pumps, electronic systems can be turned up to unlock horsepower that's not available when the stock programming is in control. Based on information from the sensor, the ECU will tell the injection pump to deliver fuel to the rail(s) connected to the injectors, which emit a burst of fuel (pulse) for a certain amount of time (pulse width) during a certain point in the combustion cycle (timing). With common-rail systems ('03-and-later Dodge, 6.4L Ford Power Stroke, GM Duramax), the fuel in the rail(s) is already pressurized to at least 23,000 psi when the engine is under full load, but this can be easily upped to 29,000 psi before seals in the stock injection pump will fail. The manufacturers prefer to stay well under that limit, so an injection pulse at a stock rail pressure will contain less fuel than a pulse of the same width when the rail has extra pressure.
Crankshaft RPM/Camshaft Position
To determine the best time to inject fuel, the engine computer needs to know when the valves are open and where the cylinders are positioned. Crankshaft and camshaft position sensors in the engine send this information to the ECU, where they are added into its other calculations.
Throttle Position
Of course, the truck wants to know how you would like it to perform. You are the boss in this relationship, after all. When you mash on the accelerator pedal, the throttle-position sensor tells the ECU what you have done, uses the information it's constantly reading, and makes a calculation based on your input. With the factory settings in use, the ECU will attempt to perform to your expectations while staying within preset limits designed to protect the engine and transmission.
Transmission Input/Output
By reading the speed of the input and output shafts of the transmission, the ECU can determine how much the transmission is slipping and adjust power output. The computer also uses the information so it knows when to de-fuel in between shifts and when the lockup torque converter engages to reduce the risk of damage.
Engine and Transmission Temperatures
In addition to reading inputs from the transmission, the ECU monitors engine and transmission-fluid temperatures. This information also affects how the engine operates.