Good question, but not an easy one to answer. One of the problems is that "identical" is easy to say, but difficult to determine, and moreover changes over time. For example, many systems have differing environments for the same user in different situations -- Windows systems offer a "roaming" profile, for example. Linux systems, depending on your shell, may run different scripts upon login depending on whether the user is considered to be "interactive" or not. The latter is particularly problematic because users tend to test things when logged in interactively, unaware that key settings in their environment that they've set may be absent when running things as a daemon process under the same id.
It's also been my experience that users change things - sometimes that means that the "service account" under which your daemon processes run has become stale, and lacks the updated paths, settings, etc that users have. Or it can mean that a well-meaning user has changed something in a shared account and broken your automation.
The best practice is simply to not rely on the environment as set by user's startup scripts. Either set the environment explicitly for each step (which sounds harder than it is), or use controlled service accounts to run things where a knowledgeable individual manages a minimalistic set of login scripts.
(The above is one person's opinion, other's may have different viewpoints - I'm eager to see what others have tried and found to be useful!)