(في) is used to indicate the existence of an entity within a defined container.
The container can be spatial (box, house, neighborhood, country, solar system or even universe) temporal (second, hour, day, week or even a century) or imaginary (dream, idea, mind, science, category or even speech).
(ب) is used to indicate the cause of an effect (in the meaning of "by the use of", "by the effect of" or "by the assistance of").
في يدي فرشاة
In my hand a brush
With my hand I write