> ## Documentation Index
> Fetch the complete documentation index at: https://docs.browserbase.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Build a Box compliance intake

> Download documents with Stagehand, analyze them with Box AI, and route compliance exceptions for review.

This guide runs a complete document intake. Stagehand downloads an SDS and sample pesticide-label PDF in a Browserbase session. Box stores the files, extracts their compliance fields, and records the review decision.

<Steps titleSize="h3">
  <Step title="Get your Browserbase API key">
    Copy your API key from [Browserbase settings](https://www.browserbase.com/settings).
  </Step>

  <Step title="Create a Box Server app">
    Open the [Box Developer Console](https://app.box.com/developers/console), then create a **Server Authentication** app with **Client Credentials Grant**.

    Enable these application scopes:

    * Read all files and folders stored in Box
    * Write all files and folders stored in Box
    * Manage AI

    Authorize the app in your Box enterprise. Copy the client ID, client secret, and enterprise ID for the next step.

    <Note>
      Client Credentials Grant creates short-lived access tokens for the app's service account at runtime. You don't need an interactive login or a Box Developer Token.
    </Note>
  </Step>

  <Step title="Share a Box folder">
    Find the service account email in the Box app details. Invite that account to the destination folder with the **Editor** role.

    Copy the folder ID from its Box URL:

    ```text theme={null}
    https://app.box.com/folder/123456789
                               └──────── BOX_FOLDER_ID
    ```

    The workflow can access only the content available to this service account.
  </Step>

  <Step title="Install the example">
    Clone the integrations repository and install the Box example:

    ```bash theme={null}
    git clone https://github.com/browserbase/integrations.git
    cd integrations/examples/integrations/box
    pnpm install --ignore-workspace
    ```
  </Step>

  <Step title="Configure environment variables">
    Create your local environment file:

    ```bash theme={null}
    cp .env.example .env
    ```

    Add your Browserbase and Box credentials:

    ```env .env theme={null}
    BROWSERBASE_API_KEY=your_browserbase_api_key
    BOX_CLIENT_ID=your_box_client_id
    BOX_CLIENT_SECRET=your_box_client_secret
    BOX_ENTERPRISE_ID=your_box_enterprise_id
    BOX_FOLDER_ID=your_box_folder_id
    ```

    The example includes default SDS and label sources. Override them when you want to process a different pair:

    ```env .env theme={null}
    SDS_PAGE_URL=https://example.com/safety-data-sheet
    SDS_LINK_TEXT=Download safety data sheet
    LABEL_PAGE_URL=https://example.com/product-label
    LABEL_LINK_TEXT=Download product label
    ```

    Each source link must start a browser download. Stagehand clicks the link, and the Browserbase Downloads API exposes the resulting file.
  </Step>

  <Step title="Run the intake">
    Start the workflow:

    ```bash theme={null}
    pnpm start
    ```

    The command prints:

    * A Browserbase Session Inspector URL
    * The cited Box AI answer
    * Extracted metadata, confidence scores, and source references
    * The `APPROVED` or `NEEDS_REVIEW` decision
    * Links to the uploaded Box files
  </Step>
</Steps>

## Review the workflow

The example uses Stagehand to find and click each document link. Browserbase stores the remote browser downloads, and the workflow retrieves the original bytes through the Downloads API.

After it uploads the files, the workflow calls Box AI to:

* Answer a safety question about the SDS with citations
* Extract structured SDS fields
* Extract label fields, including text embedded in the label artwork
* Return confidence scores and references for review

The compliance check normalizes the EPA registration numbers, compares them, and confirms that the SDS includes a revision date. Any missing or conflicting value produces `NEEDS_REVIEW`.

Finally, the workflow adds these values to each file's global `properties` metadata:

* Extracted compliance fields
* Browserbase session ID
* Source URL
* Document role
* Compliance status

## Troubleshooting

### Box AI isn't ready

Box may need time to index a new file. The example retries readiness, rate-limit, and server responses with bounded exponential backoff before it stops.

### The browser opens a file instead of downloading it

Confirm that the source link starts a browser download. Update the source URL and accessible link name in `.env`, then use the Session Inspector to confirm that Stagehand clicks the expected link.

### Box returns a permissions error

Confirm that the enterprise authorized the Server app, the app has the required file and Box AI scopes, and the destination folder grants its service account the Editor role.

## Next steps

<CardGroup cols={2}>
  <Card title="Browserbase downloads" icon="download" href="/platform/browser/files/downloads">
    Learn how to retrieve files from Browserbase sessions.
  </Card>

  <Card title="Stagehand quickstart" icon="wand-magic-sparkles" href="/welcome/quickstarts/stagehand">
    Build browser agents with Stagehand and Browserbase.
  </Card>

  <Card title="Box AI structured extraction" icon="table-list" href="https://developer.box.com/reference/post-ai-extract-structured">
    Review the Box API fields, OCR support, and response format.
  </Card>

  <Card title="Box Client Credentials Grant" icon="key" href="https://developer.box.com/guides/authentication/client-credentials">
    Configure unattended authentication for a Box service account.
  </Card>
</CardGroup>
