The least number of boxes and bags needed are 3 and 2 respectively.
Step-by-step explanation
Suppose, the number of boxes is
and the number of bags is

Given that, pencils come in 8 in a box and erasers come 12 in a bag.
So, the total number of pencils in
number of boxes
and the total number of erasers in
number of bags

As there are total 24 students and each student needs one pencil and one eraser to take a test, so...

and

So, the least number of boxes and bags needed are 3 and 2 respectively.