# How do I keep an agent's browser logged in between sessions?

> Keep the browser profile on a disk that outlives each session and log in once yourself. A Sanbox Browser Computer keeps cookies and signed-in sessions across stop and resume.

- Source: Sanbox knowledge base, by Sanlabs GmbH
- URL: https://sanbox.cloud/kb/browser/keep-an-agents-browser-logged-in/
- Type: how-to
- Section: Browser agents
- Language: en
- Published: 2026-11-06
- Updated: 2026-11-06

A browser stays logged in when its profile, the cookies and local storage it writes, is kept on a disk that outlives the session, and you log in once yourself. On Sanbox, a Browser Computer keeps its Chromium profile on the Computer's saved disk: you take over the live browser in the console to log in, stop the Computer when the work is done, and resume it later still signed in. Sites can still end a session on their own, for example after a timeout or with a new two-factor prompt.

## Run this with your agent

```text
Read https://sanbox.cloud/kb/browser/keep-an-agents-browser-logged-in.md and follow it to set up a Browser Computer that stays logged in.
If the Sanbox CLI is missing, install it with `npm install -g @sanlabs/sanbox-cli@latest`
and sign in with `sanbox login`. Show me each command before you create, stop or delete a Computer.
```

## What keeps the login?

| What | Stop, then resume | Fork | Snapshot | Delete |
|---|---|---|---|---|
| Cookies and local storage | Kept | Copied | Copied | Removed |
| Signed-in sessions the site keeps in cookies | Kept, until the site expires them | Copied | Copied | Removed |
| Open tabs | Usually restored by Chromium | Usually restored | Usually restored | Removed |
| In-memory page state, unsaved form input | Lost | Not copied | Not copied | Removed |

On stop, Sanbox closes Chromium cleanly so it writes its cookies and session files before the disk is saved. If logins don't survive a stop, create a new Browser Computer template.

## Steps

### 1. Allow the site's hosts

Computers deny outbound traffic by default. List every host the site loads, including its login and asset hosts, in `browser-policy.json`:

```json
{
  "default_action": "deny",
  "rules": [
    { "destination": "app.example.com", "ports": [{ "from": 443, "to": 443 }] },
    { "destination": "login.example.com", "ports": [{ "from": 443, "to": 443 }] },
    { "destination": "static.example.com", "ports": [{ "from": 443, "to": 443 }] }
  ]
}
```

A template holds at most 16 rules of its own, so list only the hosts the task needs. If the site signs you in through another provider, add that provider's hosts too.

### 2. Create a Browser Computer template

```bash
sanbox templates create --name "Logged-in browser" --type browser-computer \
  --model-provider <provider-id> --model <model-id> \
  --network-policy browser-policy.json --json
sanbox templates validate <template-id> --json
```

`runnable: true` means the template can start. It doesn't check that the policy covers the site.

### 3. Start one Computer and keep it

```bash
sanbox run --template <template-id> --external-run-id browser-example-app --json
sanbox runs get <run-id> --json
```

Keep using this one Computer for the site. A new Computer from the same template starts with an empty profile.

### 4. Log in yourself

Open the run in the [console](https://console.sanbox.cloud). The chat sits beside the live browser. Take control of the browser, or turn on **Mouse & keyboard** if your template shows that switch, then open the site, type your username and password, and pass any two-factor prompt. With the switch on, the agent keeps working while you type, so ask it in chat to wait until you're done, and you can paste text with Cmd+V or Ctrl+V, up to 16,000 characters.

Don't put passwords in the task or the chat. When you're signed in, hand control back or turn the switch off, and tell the agent what to do.

### 5. Stop and resume

```bash
sanbox runs stop <run-id> --wait --json
sanbox runs resume <run-id> --wait --json
```

After the resume, open the site again in the live view to check that you're still signed in. Stop keeps the disk, including the profile, but not RAM or running processes. Nothing stops the Computer for you; it stays on until you stop it.

### 6. Give it work

Send tasks to this same Computer in the console chat, or from your own code through `sanbox opencode connect <run-id> --expires 1h --json` and the OpenCode SDK. Starting a new Computer with `sanbox run` gives you a fresh, signed-out profile unless it comes from a snapshot (below).

## Snapshot it

A fork or a snapshot copies the signed-in profile, so every copy can act as you:

```bash
sanbox runs stop <run-id> --wait --json
sanbox runs fork <run-id> --request-key <uuid> --wait --json
sanbox snapshots create --run <run-id> --name example-app-signed-in --wait
sanbox run --snapshot example-app-signed-in --json
```

The source must be stopped. Anyone in your organisation who can start runs from the snapshot gets the session. Many sites don't allow one session to be used in several places, so check their terms before you copy a signed-in profile.

## Lock down egress

Keep the policy to the site's own hosts. A blocked request names the host it couldn't reach, so add hosts one by one as the page shows them. Inbound access stays off; nothing on the Computer becomes public.

## What this doesn't do

- It doesn't stop sites from ending sessions. Sites can expire cookies, ask for two-factor again, or sign you out when they see a new device or network. Sanbox doesn't offer static egress IPs.
- It doesn't solve CAPTCHAs or other bot checks.
- It doesn't store your password. The browser keeps whatever the site saves in cookies, and the agent can use that session for anything the account allows. Use an account with only the access the task needs.
- Developers, Admins and Owners in your organisation can operate any run, including its browser.
- Delete removes the disk and the profile with it.
- Check the site's terms; some don't allow automated access.

## Related

- [Can I watch my AI agent's browser live and take over?](https://sanbox.cloud/kb/browser/watch-and-take-over-your-agents-browser/)
- [What survives when an agent's computer stops?](https://sanbox.cloud/kb/agent-computers/what-survives-a-stop/)
- [How do I restrict which domains an AI agent can reach?](https://sanbox.cloud/kb/security/restrict-which-domains-an-agent-can-reach/)
- [Why can't my AI agent reach a website or package registry?](https://sanbox.cloud/kb/errors/why-cant-my-agent-reach-a-website/)

## Next step

Talk to us at sales@sanlabs.ai. Sanlabs' forward-deployed engineers build agent use cases with your team, with experience in aviation, pharmaceuticals, supply chain and logistics, and internal admin workflows. How we work: https://sanbox.cloud/kb/teams/forward-deployed-engineering.md

Existing customers can use Sanbox from a coding agent: install the CLI with `npm install -g @sanlabs/sanbox-cli@latest`, sign in with `sanbox login`, then run `sanbox skill` for the full agent guide.
