Microsoft Fara Tutorial: Run a Browser-Use Agent in Google Colab with a Mock OpenAI-Compatible Endpoint 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. 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 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. python import os import sys import json import time import socket import subprocess import importlib from pathlib import Path USE REAL FARA ENDPOINT = False REAL FARA BASE URL = "http://localhost:5000/v1" REAL FARA API KEY = "not-needed" REAL FARA MODEL = "microsoft/Fara-7B" TASK = "Open example.com and tell me what the page is." WORKDIR = Path "/content/fara tutorial" REPO DIR = Path "/content/fara" REPO SRC = REPO DIR / "src" OUTPUT DIR = WORKDIR / "outputs" ENDPOINT CONFIG PATH = WORKDIR / "endpoint config.json" MOCK SERVER FILE = WORKDIR / "mock fara endpoint.py" WORKDIR.mkdir parents=True, exist ok=True OUTPUT DIR.mkdir parents=True, exist ok=True We 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. python def run cmd cmd, cwd=None, check=True, env=None : print f"\n$ {cmd}" result = subprocess.run cmd, shell=True, cwd=str cwd if cwd else None, text=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=env, print result.stdout if check and result.returncode = 0: raise RuntimeError f"Command failed with exit code {result.returncode}: {cmd}" return result def wait for port host, port, timeout=60 : start = time.time while time.time - start < timeout: try: with socket.create connection host, port , timeout=2 : return True except OSError: time.sleep 1 return False print "Python:", sys.version print "Working directory:", WORKDIR We 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. os.chdir "/content" if REPO DIR.exists : print "Fara repo already exists. Pulling latest changes..." run cmd "git pull", cwd=REPO DIR, check=False else: run cmd "git clone https://github.com/microsoft/fara.git /content/fara" print "\nInstalling Fara and tutorial dependencies..." run cmd f'{sys.executable} -m pip install -q "setuptools<82" wheel pip', check=True, run cmd f'{sys.executable} -m pip install -q -e /content/fara fastapi uvicorn requests pillow', check=True, if str REPO SRC not in sys.path: sys.path.insert 0, str REPO SRC print "\nInstalling Playwright Firefox browser and system dependencies..." run cmd f"{sys.executable} -m playwright install --with-deps firefox", check=True, We 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. python print "\nInspecting Fara package files..." try: import fara print "Imported fara from:", getattr fara, " file ", "unknown" except Exception as e: print "Could not import fara:", repr e print "\nAvailable files inside /content/fara/src/fara:" if REPO SRC / "fara" .exists : for p in sorted REPO SRC / "fara" .glob " .py" : print "-", p.name else: print "Could not find /content/fara/src/fara" print "\nTrying to inspect Fara action definitions..." try: fara agent = importlib.import module "fara.fara agent" action defs = getattr fara agent, "FARA ACTION DEFINITIONS", None if action defs: print "\nFara action space:" for action name, arg names in action defs.items : args = ", ".join sorted arg names if arg names else "no arguments" print f"- {action name}: {args}" else: print "FARA ACTION DEFINITIONS was not found. Continuing because this step is optional." except Exception as e: print "Could not import fara.fara agent directly:", repr e print "Continuing because this inspection step is optional." We 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. python mock server code = r''' from fastapi import FastAPI, Request import time app = FastAPI STATE = {"calls": 0} @app.post "/v1/chat/completions" async def chat completions request: Request : payload = await request.json STATE "calls" += 1 model name = payload.get "model", "mock-fara-7b" if STATE "calls" == 1: content = "I will open a stable public test page so the browser-control loop can be demonstrated.\n" "{\"name\":\"computer\",\"arguments\":{\"action\":\"visit url\",\"url\":\"https://example.com\"}}" else: content = "The browser has opened Example Domain, a stable demonstration page used for documentation and examples.\n" "{\"name\":\"computer\",\"arguments\":{\"action\":\"terminate\",\"status\":\"success\"}}" return { "id": f"chatcmpl-mock-{STATE 'calls' }", "object": "chat.completion", "created": int time.time , "model": model name, "choices": { "index": 0, "message": { "role": "assistant", "content": content }, "finish reason": "stop" } , "usage": { "prompt tokens": 100, "completion tokens": 50, "total tokens": 150 } } ''' MOCK SERVER FILE.write text mock server code print f"\nMock endpoint written to: {MOCK SERVER FILE}" if USE REAL FARA ENDPOINT: endpoint config = { "model": REAL FARA MODEL, "base url": REAL FARA BASE URL, "api key": REAL FARA API KEY, } else: endpoint config = { "model": "mock-fara-7b", "base url": "http://127.0.0.1:8001/v1", "api key": "not-needed", } ENDPOINT CONFIG PATH.write text json.dumps endpoint config, indent=2 print "\nEndpoint config:" print ENDPOINT CONFIG PATH.read text mock process = None if not USE REAL FARA ENDPOINT: print "\nStarting mock OpenAI-compatible endpoint..." mock process = subprocess.Popen sys.executable, "-m", "uvicorn", "mock fara endpoint:app", "--host", "127.0.0.1", "--port", "8001", , cwd=str WORKDIR , stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True, if not wait for port "127.0.0.1", 8001, timeout=60 : if mock process and mock process.stdout: print mock process.stdout.read raise RuntimeError "Mock endpoint did not start on port 8001." print "Mock endpoint is running at http://127.0.0.1:8001/v1" else: print "\nUsing real Fara endpoint. Make sure it is reachable." We 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. print "\nRunning Fara browser agent..." fara command = f'fara-cli ' f'--task "{TASK}" ' f'--endpoint config "{ENDPOINT CONFIG PATH}"' agent result = run cmd fara command, cwd=REPO DIR, check=False if agent result.returncode = 0: print "\nfara-cli failed, trying module form..." fara command = f'{sys.executable} -m fara.run fara ' f'--task "{TASK}" ' f'--endpoint config "{ENDPOINT CONFIG PATH}"' agent result = run cmd fara command, cwd=REPO DIR, check=False print "\nFara command exit code:", agent result.returncode print "\nSaved tutorial outputs:" if OUTPUT DIR.exists : files = sorted OUTPUT DIR.glob " " if files: for path in files: print "-", path else: print "No files saved in output directory." else: print "Output directory does not exist." real usage notes = """ ============================================================================ How to switch this notebook from mock mode to real Fara-7B ============================================================================ Option A: Azure Foundry endpoint Set: USE REAL FARA ENDPOINT = True REAL FARA BASE URL = "https://your-endpoint.inference.ml.azure.com/" REAL FARA API KEY = "YOUR AZURE FOUNDRY KEY" REAL FARA MODEL = "Fara-7B" Option B: self-host with vLLM on a GPU machine Run this separately on the GPU machine: vllm serve "microsoft/Fara-7B" --port 5000 --dtype auto Then set: USE REAL FARA ENDPOINT = True REAL FARA BASE URL = "http://localhost:5000/v1" REAL FARA API KEY = "not-needed" REAL FARA MODEL = "microsoft/Fara-7B" Option C: LM Studio or Ollama Load a compatible Fara-7B model and enable an OpenAI-compatible local server. Example base URLs: LM Studio: http://localhost:1234/v1 Ollama-style OpenAI server: http://localhost:11434/v1 Important: Browser agents should be tested in sandboxed environments only. Avoid private accounts, payments, credentials, and high-risk websites. ============================================================================ """ print real usage notes if mock process is not None: print "\nStopping mock endpoint..." mock process.terminate try: mock process.wait timeout=10 except subprocess.TimeoutExpired: mock process.kill print "Mock endpoint stopped." print "\nTutorial complete." We 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. In 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. Check out the Full Codes here. Also, feel free to follow us on and don’t forget to join our Twitter https://x.com/intent/follow?screen name=marktechpost and Subscribe to 150k+ ML SubReddit https://www.reddit.com/r/machinelearningnews/ . Wait are you on telegram? our Newsletter https://www.aidevsignals.com/ 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 Sana 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. - Sana Hassan - Sana Hassan - Sana Hassan - Sana Hassan