When I run this fabfile.py...
fabfile.py
from fabric.api import env, run, local, cd def setenv(foo): env.hosts = [\'myhost\'] def mycmd(foo): setenv(
Have you tried to used the hosts decorator?
from fabric.api import env, run, hosts @hosts('myhost') def mycmd(foo): print(env.hosts) run('ls')