What conditions in a ecosystem, specifically where on a food chain and what kind of diet, would likely result in a creature gaining the necessary brain structure, and opposable digits, to become sentient? I am aware that defining sentience is quite difficult, so feel free to use you own judgment as to whether it means a certain level I.Q., a certin level of awareness, or some other reasonable scale.
Self awareness is probably most beneficial for creatures that live with others of their kind, a creature needs to understand theory of mind before it can consider what others think of it and what it thinks of itself, i.e. its identity. Many social animals have the capacity to recognise and interact with others preferentially (including individual humans) and it's only these species that'll exhibit altruistic behaviours, because only they understand the value of making a good impression.
You can't build trust with a snake it simply lacks the capacity to differentiate you from its environment, as far as a snake is concerned you're either prey, a predator or irrelevant. Whether you've been feeding it all its life or its just met you for the first time today is irrelevant, the snake simply cannot recognise you as an individual.
The first condition for sentience is a plentiful source of protein, meat protein is best but not strictly necessary as long as the source is easy to chew or mash between rocks and then eat. Brains require a high level of protein and other nutrients, fruit and leaves won't do it, and potato's, yams and sweet potatoes are hard to chew without proper preparation. Meat can be allowed to rot a little, can be softened by hitting it against rocks, or by lightly roasting it on a fire for a few minutes, and is high in protein, making it the ideal food. Large plentiful bugs could fill in for animal meat, as they're also high in protein.
Opposable digits are harder, as they're more of a lucky fluke and many animals can do plenty of things with their paws. The best bet would be having the creature living in an ecosystem where they need to either climb trees, work around thick underbrush, roots or thorns, or have them climbing lots of rocky terrain where they also need to move rocks to get food. Each of these ecosystems would make having more hand dexterity and being able to wrap a hand around something to move it out of the way, pull themselves up, and grab food would encourage an opposable thumb or finger.