Authenticate the Box CLI on machines without a browser using manual code entry. Use theDocumentation Index
Fetch the complete documentation index at: https://developer.box.com/llms.txt
Use this file to discover all available pages before exploring further.
--code flag to authenticate the Box CLI in
headless environments such as remote servers, containers,
or CI/CD pipelines where no browser is available.
Prerequisites
- The Box CLI is .
- You have access to a browser on a separate machine (for example, your laptop) to complete the authorization step.
How it works
The standardbox login command opens a browser on the
same machine and starts a local callback server to
receive the authorization response automatically. In
headless environments, neither is possible.
The --code flag changes the login flow:
- The CLI prints an authorization URL instead of opening a browser.
- No local callback server is started.
- After you authorize in a browser on another machine, you manually copy the resulting code and state back into the CLI.
Authenticate
Step 1: Start login with the --code flag
On the headless machine, run:
Step 2: Authorize in a browser on another machine
Copy the authorization URL that the CLI printed, then open it in a browser on a machine that has one. Sign in to Box and select Grant Access to Box.Step 3: Copy the code and state from the redirect URL
After you grant access, the browser redirects to alocalhost callback URL. Because no callback server is
running on the headless machine, the page does not load
and the browser displays a connection error.
This is expected.
Look at the URL in the browser’s address bar. It
contains the values you need:
code and state from this URL.
Step 4: Enter the codes in the CLI
Return to the terminal on the headless machine and paste thecode and state values when the CLI prompts for
them.
After the CLI confirms successful authentication, you
are ready to run commands.
Step 5: Verify the setup
Using --code on a machine with a browser
The --code flag is intended for headless environments.
If you use it on a machine that has a browser:
- The CLI still prints the authorization URL.
- After you authorize, the browser redirects to the
callback URL. Because
--codeskips starting the local callback server, the redirect page does not load and the browser shows a connection error. - The CLI continues to wait for you to manually enter the
codeandstatevalues, just as it would in a headless environment.
box login without --code for a smoother experience.