{"slug": "microsoft-fara-tutorial-run-a-browser-use-agent-in-google-colab-with-a-mock", "title": "Microsoft Fara Tutorial: Run a Browser-Use Agent in Google Colab with a Mock OpenAI-Compatible Endpoint", "summary": "Microsoft released a tutorial demonstrating how to run a browser-use agent workflow using Microsoft Fara in Google Colab. The tutorial guides users through setting up a mock OpenAI-compatible endpoint to test browser actions before deploying the full Fara-7B model, with flexible configuration options for connecting to Azure Foundry, vLLM, LM Studio, or Ollama. This approach allows developers to validate agent loops and browser interactions without requiring heavy model infrastructure upfront.", "body_md": "In this [tutorial](https://github.com/MARKTECHPOST-AI-MEDIA-INC/AI-Agents-Projects-Tutorials/blob/main/Agentic%20AI%20Codes/microsoft_fara_colab_browser_agent_workflow_marktechpost.py), we set up[ Microsoft Fara](https://github.com/microsoft/fara)\n\n**in Google Colab and run a browser-use workflow from start to finish. We begin by cloning the repository, installing the package, preparing Playwright, and verifying that the installed Fara files work even when the package layout changes. Instead of immediately relying on a heavy Fara-7B deployment, we create a small mock OpenAI-compatible endpoint that returns valid browser actions. This lets us test the same agent loop that Fara uses for real tasks, including sending a task, receiving model-style action responses, and executing those actions through the browser. We also keep the endpoint configuration flexible, so the same notebook can later connect to Azure Foundry, vLLM, LM Studio, or Ollama when we want to use the real Fara-7B model.**\n\n``` python\nimport os\nimport sys\nimport json\nimport time\nimport socket\nimport subprocess\nimport importlib\nfrom pathlib import Path\nUSE_REAL_FARA_ENDPOINT = False\nREAL_FARA_BASE_URL = \"http://localhost:5000/v1\"\nREAL_FARA_API_KEY = \"not-needed\"\nREAL_FARA_MODEL = \"microsoft/Fara-7B\"\nTASK = \"Open example.com and tell me what the page is.\"\nWORKDIR = Path(\"/content/fara_tutorial\")\nREPO_DIR = Path(\"/content/fara\")\nREPO_SRC = REPO_DIR / \"src\"\nOUTPUT_DIR = WORKDIR / \"outputs\"\nENDPOINT_CONFIG_PATH = WORKDIR / \"endpoint_config.json\"\nMOCK_SERVER_FILE = WORKDIR / \"mock_fara_endpoint.py\"\nWORKDIR.mkdir(parents=True, exist_ok=True)\nOUTPUT_DIR.mkdir(parents=True, exist_ok=True)\n```\n\nWe import the required Python libraries and define the main configuration values for the tutorial. We decide whether to use the mock endpoint or connect to a real Fara endpoint, and we set the browser task that the agent needs to perform. We also create the working folders and file paths for the repository, endpoint configuration, mock server, and output files.\n\n``` python\ndef run_cmd(cmd, cwd=None, check=True, env=None):\n   print(f\"\\n$ {cmd}\")\n   result = subprocess.run(\n       cmd,\n       shell=True,\n       cwd=str(cwd) if cwd else None,\n       text=True,\n       stdout=subprocess.PIPE,\n       stderr=subprocess.STDOUT,\n       env=env,\n   )\n   print(result.stdout)\n   if check and result.returncode != 0:\n       raise RuntimeError(f\"Command failed with exit code {result.returncode}: {cmd}\")\n   return result\ndef wait_for_port(host, port, timeout=60):\n   start = time.time()\n   while time.time() - start < timeout:\n       try:\n           with socket.create_connection((host, port), timeout=2):\n               return True\n       except OSError:\n           time.sleep(1)\n   return False\nprint(\"Python:\", sys.version)\nprint(\"Working directory:\", WORKDIR)\n```\n\nWe define a command runner that lets us execute shell commands in the notebook and view the output clearly. We also create a helper function that checks whether a server is active on a given port before the next step runs. We then print the Python version and working directory to confirm that the Colab environment is set up correctly.\n\n```\nos.chdir(\"/content\")\nif REPO_DIR.exists():\n   print(\"Fara repo already exists. Pulling latest changes...\")\n   run_cmd(\"git pull\", cwd=REPO_DIR, check=False)\nelse:\n   run_cmd(\"git clone https://github.com/microsoft/fara.git /content/fara\")\nprint(\"\\nInstalling Fara and tutorial dependencies...\")\nrun_cmd(\n   f'{sys.executable} -m pip install -q \"setuptools<82\" wheel pip',\n   check=True,\n)\nrun_cmd(\n   f'{sys.executable} -m pip install -q -e /content/fara fastapi uvicorn requests pillow',\n   check=True,\n)\nif str(REPO_SRC) not in sys.path:\n   sys.path.insert(0, str(REPO_SRC))\nprint(\"\\nInstalling Playwright Firefox browser and system dependencies...\")\nrun_cmd(\n   f\"{sys.executable} -m playwright install --with-deps firefox\",\n   check=True,\n)\n```\n\nWe clone the Microsoft Fara repository into Colab, or pull the latest version if the repository already exists. We install Fara along with the supporting packages needed for the mock endpoint and browser workflow. We also install Playwright Firefox support so the agent can control a browser during execution.\n\n``` python\nprint(\"\\nInspecting Fara package files...\")\ntry:\n   import fara\n   print(\"Imported fara from:\", getattr(fara, \"__file__\", \"unknown\"))\nexcept Exception as e:\n   print(\"Could not import fara:\", repr(e))\nprint(\"\\nAvailable files inside /content/fara/src/fara:\")\nif (REPO_SRC / \"fara\").exists():\n   for p in sorted((REPO_SRC / \"fara\").glob(\"*.py\")):\n       print(\"-\", p.name)\nelse:\n   print(\"Could not find /content/fara/src/fara\")\nprint(\"\\nTrying to inspect Fara action definitions...\")\ntry:\n   fara_agent = importlib.import_module(\"fara.fara_agent\")\n   action_defs = getattr(fara_agent, \"FARA_ACTION_DEFINITIONS\", None)\n   if action_defs:\n       print(\"\\nFara action space:\")\n       for action_name, arg_names in action_defs.items():\n           args = \", \".join(sorted(arg_names)) if arg_names else \"no arguments\"\n           print(f\"- {action_name}: {args}\")\n   else:\n       print(\"FARA_ACTION_DEFINITIONS was not found. Continuing because this step is optional.\")\nexcept Exception as e:\n   print(\"Could not import fara.fara_agent directly:\", repr(e))\n   print(\"Continuing because this inspection step is optional.\")\n```\n\nWe inspect the installed Fara package and check where it is being imported from in the notebook. We list the Python files in the Fara source folder to understand the current package structure. We then try to load the Fara action definitions safely, while keeping the tutorial running even if the import path changes.\n\n``` python\nmock_server_code = r'''\nfrom fastapi import FastAPI, Request\nimport time\napp = FastAPI()\nSTATE = {\"calls\": 0}\n@app.post(\"/v1/chat/completions\")\nasync def chat_completions(request: Request):\n   payload = await request.json()\n   STATE[\"calls\"] += 1\n   model_name = payload.get(\"model\", \"mock-fara-7b\")\n   if STATE[\"calls\"] == 1:\n       content = (\n           \"I will open a stable public test page so the browser-control loop can be demonstrated.\\n\"\n           \"{\\\"name\\\":\\\"computer\\\",\\\"arguments\\\":{\\\"action\\\":\\\"visit_url\\\",\\\"url\\\":\\\"https://example.com\\\"}}\"\n       )\n   else:\n       content = (\n           \"The browser has opened Example Domain, a stable demonstration page used for documentation and examples.\\n\"\n           \"{\\\"name\\\":\\\"computer\\\",\\\"arguments\\\":{\\\"action\\\":\\\"terminate\\\",\\\"status\\\":\\\"success\\\"}}\"\n       )\n   return {\n       \"id\": f\"chatcmpl-mock-{STATE['calls']}\",\n       \"object\": \"chat.completion\",\n       \"created\": int(time.time()),\n       \"model\": model_name,\n       \"choices\": [\n           {\n               \"index\": 0,\n               \"message\": {\n                   \"role\": \"assistant\",\n                   \"content\": content\n               },\n               \"finish_reason\": \"stop\"\n           }\n       ],\n       \"usage\": {\n           \"prompt_tokens\": 100,\n           \"completion_tokens\": 50,\n           \"total_tokens\": 150\n       }\n   }\n'''\nMOCK_SERVER_FILE.write_text(mock_server_code)\nprint(f\"\\nMock endpoint written to: {MOCK_SERVER_FILE}\")\nif USE_REAL_FARA_ENDPOINT:\n   endpoint_config = {\n       \"model\": REAL_FARA_MODEL,\n       \"base_url\": REAL_FARA_BASE_URL,\n       \"api_key\": REAL_FARA_API_KEY,\n   }\nelse:\n   endpoint_config = {\n       \"model\": \"mock-fara-7b\",\n       \"base_url\": \"http://127.0.0.1:8001/v1\",\n       \"api_key\": \"not-needed\",\n   }\nENDPOINT_CONFIG_PATH.write_text(json.dumps(endpoint_config, indent=2))\nprint(\"\\nEndpoint config:\")\nprint(ENDPOINT_CONFIG_PATH.read_text())\nmock_process = None\nif not USE_REAL_FARA_ENDPOINT:\n   print(\"\\nStarting mock OpenAI-compatible endpoint...\")\n   mock_process = subprocess.Popen(\n       [\n           sys.executable,\n           \"-m\",\n           \"uvicorn\",\n           \"mock_fara_endpoint:app\",\n           \"--host\",\n           \"127.0.0.1\",\n           \"--port\",\n           \"8001\",\n       ],\n       cwd=str(WORKDIR),\n       stdout=subprocess.PIPE,\n       stderr=subprocess.STDOUT,\n       text=True,\n   )\n   if not wait_for_port(\"127.0.0.1\", 8001, timeout=60):\n       if mock_process and mock_process.stdout:\n           print(mock_process.stdout.read())\n       raise RuntimeError(\"Mock endpoint did not start on port 8001.\")\n   print(\"Mock endpoint is running at http://127.0.0.1:8001/v1\")\nelse:\n   print(\"\\nUsing real Fara endpoint. Make sure it is reachable.\")\n```\n\nWe create a mock OpenAI-compatible endpoint that returns valid Fara-style browser actions. We write the endpoint configuration file so Fara knows whether to call the mock server or a real Fara-7B endpoint. We then start the mock server in the background and wait until it is ready to receive requests.\n\n```\nprint(\"\\nRunning Fara browser agent...\")\nfara_command = (\n   f'fara-cli '\n   f'--task \"{TASK}\" '\n   f'--endpoint_config \"{ENDPOINT_CONFIG_PATH}\"'\n)\nagent_result = run_cmd(fara_command, cwd=REPO_DIR, check=False)\nif agent_result.returncode != 0:\n   print(\"\\nfara-cli failed, trying module form...\")\n   fara_command = (\n       f'{sys.executable} -m fara.run_fara '\n       f'--task \"{TASK}\" '\n       f'--endpoint_config \"{ENDPOINT_CONFIG_PATH}\"'\n   )\n   agent_result = run_cmd(fara_command, cwd=REPO_DIR, check=False)\nprint(\"\\nFara command exit code:\", agent_result.returncode)\nprint(\"\\nSaved tutorial outputs:\")\nif OUTPUT_DIR.exists():\n   files = sorted(OUTPUT_DIR.glob(\"*\"))\n   if files:\n       for path in files:\n           print(\"-\", path)\n   else:\n       print(\"No files saved in output directory.\")\nelse:\n   print(\"Output directory does not exist.\")\nreal_usage_notes = \"\"\"\n============================================================================\nHow to switch this notebook from mock mode to real Fara-7B\n============================================================================\nOption A: Azure Foundry endpoint\nSet:\nUSE_REAL_FARA_ENDPOINT = True\nREAL_FARA_BASE_URL = \"https://your-endpoint.inference.ml.azure.com/\"\nREAL_FARA_API_KEY = \"YOUR_AZURE_FOUNDRY_KEY\"\nREAL_FARA_MODEL = \"Fara-7B\"\nOption B: self-host with vLLM on a GPU machine\nRun this separately on the GPU machine:\nvllm serve \"microsoft/Fara-7B\" --port 5000 --dtype auto\nThen set:\nUSE_REAL_FARA_ENDPOINT = True\nREAL_FARA_BASE_URL = \"http://localhost:5000/v1\"\nREAL_FARA_API_KEY = \"not-needed\"\nREAL_FARA_MODEL = \"microsoft/Fara-7B\"\nOption C: LM Studio or Ollama\nLoad a compatible Fara-7B model and enable an OpenAI-compatible local server.\nExample base URLs:\nLM Studio: http://localhost:1234/v1\nOllama-style OpenAI server: http://localhost:11434/v1\nImportant:\nBrowser agents should be tested in sandboxed environments only.\nAvoid private accounts, payments, credentials, and high-risk websites.\n============================================================================\n\"\"\"\nprint(real_usage_notes)\nif mock_process is not None:\n   print(\"\\nStopping mock endpoint...\")\n   mock_process.terminate()\n   try:\n       mock_process.wait(timeout=10)\n   except subprocess.TimeoutExpired:\n       mock_process.kill()\n   print(\"Mock endpoint stopped.\")\nprint(\"\\nTutorial complete.\")\n```\n\nWe run the Fara browser agent using fara-cli and use the module command as a fallback if the CLI call fails. We print the result, check any generated output files, and include the settings needed to switch from mock mode to a real Fara-7B deployment. We finally stop the mock endpoint and close the tutorial cleanly.\n\nIn conclusion, we have a Colab-ready Fara setup that demonstrates the main browser-control pipeline without requiring GPU resources or a live model server. We installed the framework, prepared the browser runtime, safely inspected the action setup, started a local mock endpoint, and ran the Fara CLI on a simple web task. The mock endpoint helps us verify that the agent loop, endpoint format, and browser execution flow are working before moving to a real model deployment. We also left the code structured so switching from mock mode to Fara-7B only requires changing the endpoint settings.\n\nCheck out the ** Full Codes here. **Also, feel free to follow us on\n\n**and don’t forget to join our**[Twitter](https://x.com/intent/follow?screen_name=marktechpost)\n\n**and Subscribe to**\n\n[150k+ ML SubReddit](https://www.reddit.com/r/machinelearningnews/)**. Wait! are you on telegram?**\n\n[our Newsletter](https://www.aidevsignals.com/)\n\n[now you can join us on telegram as well.](https://t.me/machinelearningresearchnews)Need to partner with us for promoting your GitHub Repo OR Hugging Face Page OR Product Release OR Webinar etc.? [Connect with us](https://forms.gle/wbash1wF6efRj8G58)\n\nSana Hassan, a consulting intern at Marktechpost and dual-degree student at IIT Madras, is passionate about applying technology and AI to address real-world challenges. With a keen interest in solving practical problems, he brings a fresh perspective to the intersection of AI and real-life solutions.\n\n- Sana Hassan\n- Sana Hassan\n- Sana Hassan\n- Sana Hassan", "url": "https://wpnews.pro/news/microsoft-fara-tutorial-run-a-browser-use-agent-in-google-colab-with-a-mock", "canonical_source": "https://www.marktechpost.com/2026/06/05/microsoft-fara-tutorial-run-a-browser-use-agent-in-google-colab-with-a-mock-openai-compatible-endpoint/", "published_at": "2026-06-05 09:04:55+00:00", "updated_at": "2026-06-05 12:04:31.284680+00:00", "lang": "en", "topics": ["ai-agents", "large-language-models", "ai-tools", "ai-infrastructure", "artificial-intelligence"], "entities": ["Microsoft Fara", "Google Colab", "Playwright", "Azure Foundry", "vLLM", "LM Studio", "Ollama", "MARKTECHPOST-AI-MEDIA-INC"], "alternates": {"html": "https://wpnews.pro/news/microsoft-fara-tutorial-run-a-browser-use-agent-in-google-colab-with-a-mock", "markdown": "https://wpnews.pro/news/microsoft-fara-tutorial-run-a-browser-use-agent-in-google-colab-with-a-mock.md", "text": "https://wpnews.pro/news/microsoft-fara-tutorial-run-a-browser-use-agent-in-google-colab-with-a-mock.txt", "jsonld": "https://wpnews.pro/news/microsoft-fara-tutorial-run-a-browser-use-agent-in-google-colab-with-a-mock.jsonld"}}