Hi Dominic ! If your background box is a rectangular shape layer you could have a simple sourceRectAtTime() expression written in it.
x = thisComp.layer("my Text Layer").sourceRectAtTime().width;
y = thisComp.layer("my Text Layer").sourceRectAtTime().height;
[x, y]
If you want to have padding to the box you can a slider control and add the slider value to the x and y like this:
x = thisComp.layer("my Text Layer").sourceRectAtTime().width;
y = thisComp.layer("my Text Layer").sourceRectAtTime().height;
pad = effect("Slider Control")("Slider");
[x+pad, y+pad]