{101¯2}〈101¯1〉 twins in magnesium is commonly activated at the room temperature under mechanical loading to accommodate arbitrary deformation. The effect of solute segregation at twin boundary on the stability of {101¯2} twins was investigated by employing first-principles calculations. A definition of twinning energy under external stress is proposed to predict the stability of twin with solid solutes at twin boundary under strains. The calculations reveal that the stability of {101¯2} twins, which is dependent on the strain path could be tailored by applying external stress with or without solid solutes at boundary. The modeling well matches the previous experimental results qualitatively. Effective solute could be selected based on the electron work function (EWF) to substitute Mg atoms in certain positions along the {101¯2} twin boundary in order to stabilize the twin.