I have two cables going into a ceiling electrical box; how can I tell which is coming from the panel?
Turn off the appropriate breaker
Make sure, with a non-contact tester, that all the wires are &quot;dead&quot;
Take pictures of the wires as currently installed, so you know what goes where
Disconnect the wires and cap them with wire nuts for safety
Turn on the breaker
Check with a non-contact tester to determine which wires have power

As others have noted, non-contact testers can give false positive readings. That is good from a safety standpoint, but sometimes gets in the way of figuring things out! If a non-contact tester shows both cables &quot;live&quot; even after they are disconnected from each other, then either one is a false positive or there is something really wrong - unusual but possible. The next test is with a multimeter to check voltage. That eliminates some, but not all, phantom readings. If a multimeter shows one of the cables with a low-but-not-zero voltage, that is typically a phantom voltage. But if it shows something close to the usual 120V, it could be real. The final test is to (carefully, doing any actual connecting/disconnecting of wires with the breaker safely off) put a load into the circuit. With a light fixture, the simplest thing is to connect only one of the cables and see what you get. If that shows &quot;live&quot; then disconnect it and connect the other cable and see what you get. Of course, a switch (if properly wired) complicates things too. Sometimes the solution is to think through the possibilities logically, carefully and methodically to figure out what is actually going on.