If you have two text layers (“Text 1” and “Text 2”) and you create a shape layer by just clicking on an empty spot in the comp window with the pen tool, if you apply this expression to the shape layer’s path, you should get a box around your text layers:
margin = 10;
L1 = thisComp.layer("Text 1");
L2 = thisComp.layer("Text 2");
r1 = L1.sourceRectAtTime(time,false);
r2 = L2.sourceRectAtTime(time,false);
ul1 = L1.toComp([r1.left, r1.top]);
lr1 = L1.toComp([r1.left + r1.width, r1.top + r1.height]);
ul2 = L2.toComp([r2.left, r2.top]);
lr2 = L2.toComp([r2.left + r2.width, r2.top + r2.height]);
top = Math.min(ul1[1], ul2[1]) - margin;
bottom = Math.max(lr1[1], lr2[1]) + margin;
left = Math.min(ul1[0], ul2[0]) - margin;
right = Math.max(lr1[0], lr2[0]) + margin;
ul = fromComp([left, top]);
ur = fromComp([right, top]);
lr = fromComp([right, bottom]);
ll = fromComp([left, bottom]);
createPath([ul, ur, lr, ll], [], [], true);