command.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. def get_remote_startup_command(
  2. port: int,
  3. sandbox_workspace_dir: str,
  4. username: str,
  5. user_id: int,
  6. plugin_args: list[str],
  7. browsergym_args: list[str],
  8. is_root: bool = False,
  9. ):
  10. base_cmd = [
  11. '/openhands/micromamba/bin/micromamba',
  12. 'run',
  13. '-n',
  14. 'openhands',
  15. 'poetry',
  16. 'run',
  17. 'python',
  18. '-u',
  19. '-m',
  20. 'openhands.runtime.action_execution_server',
  21. str(port),
  22. '--working-dir',
  23. sandbox_workspace_dir,
  24. *plugin_args,
  25. '--username',
  26. username,
  27. '--user-id',
  28. str(user_id),
  29. *browsergym_args,
  30. ]
  31. if is_root:
  32. # If running as root, set highest priority and lowest OOM score
  33. cmd_str = ' '.join(base_cmd)
  34. return [
  35. 'nice',
  36. '-n',
  37. '-20', # Highest priority
  38. 'sh',
  39. '-c',
  40. f'echo -1000 > /proc/self/oom_score_adj && exec {cmd_str}'
  41. ]
  42. else:
  43. # If not root, run with normal priority
  44. return base_cmd