Docs
Dashboard
API reference / ShellBeta

Run a command

Runs in the session's persistent shell (or a named one, or a fresh process with shell: false), after the session's setup commands finish. cd and export in a command carry to the next one (and across a stop and resume); cwd, env and credentials apply to this command only. Commands on one shell run one at a time. A command that times out is stopped with everything it started; the shell keeps its directory and exports, and background jobs keep running. Without stream, each of stdout and stderr keeps its first 64 KiB and last 448 KiB, with [… N characters not shown …] between them (truncated: true). With stream: true the reply is NDJSON as the command runs (nothing is cut); leaving stops the command. The session's exported credentials and the command's credentials are hidden in the output. 409 shell_disabled without a shell.

POST/v1/sessions/{id}/shell/exec

Request

Method and pathPOST/v1/sessions/{id}/shell/exec
Base URLhttps://api.boxline.dev
AuthenticationYour API key in the x-api-key header (or Authorization: Bearer). The examples read it from BOXLINE_API_KEY.

Path parameters

NameTypeDefaultAllowed valuesDescription
idrequiredstring––

Body

JSON with content-type: application/json. Required.

NameTypeDefaultAllowed valuesDescription
commandrequiredstring––
timeoutMsinteger120000–From 100 to 3600000.
cwdstring––The directory for this command only (inside the workspace); the shell stays where it was.
envobject––Variables for this command only.
credentialsstring[]––Credentials as environment variables for this command only (scope "shell" or "all", or shell true; one per field, and boxline-otp for its passwords); hidden in the output. Up to 50 items.
shellstring | boolean––"default" (the persistent shell), another name for a second persistent shell, or false for a fresh process.
streambooleanfalse–

More examples:

In a folder, with a variable for this command only
{"command":"ls -la","cwd":"downloads","env":{"LC_ALL":"C"}}
curl -X POST "https://api.boxline.dev/v1/sessions/$SESSION_ID/shell/exec" \  -H "x-api-key: $BOXLINE_API_KEY" \  -H "content-type: application/json" \  -d '{"command": "python3 -V"}'

Responses

200 OK

The result, or the NDJSON stream with stream:true.

  • application/json: JSON.
  • application/x-ndjson: Newline-delimited JSON (one object per line), sent as it happens.

Fields

NameTypeDefaultAllowed valuesDescription
stdoutstring––
stderrstring––
exitCodeinteger | null––
durationMsinteger––
timedOutboolean––
truncatedboolean––
Response 200
{  "stdout": "…",  "stderr": "…",  "exitCode": 0,  "durationMs": 0,  "timedOut": false,  "truncated": false}

Errors

Errors have a matching HTTP status and the same body. code is stable, so check it in your code; message is for people. See Errors and request ids.

StatusCodesWhen
400 Bad Requestinvalid_request, invalid_json, invalid_cursor, invalid_idempotency_key, invalid_extension, variables_with_extensions, terms_not_accepted, invalid_reset_token, invalid_confirmation_code, wrong_password, no_password, invalid_next, invalid_oauth_tokenThe request is not valid.
401 UnauthorizedunauthorizedMissing or invalid API key.
404 Not Foundnot_found, invite_not_found, provider_unavailableNo such thing in this project (or organization), or no such route.
409 Conflictsession_not_running, shell_disabled, browser_disabled, nothing_saved, not_resumable, invalid_state, conflict, email_taken, identity_in_use, provider_already_linked, last_sign_in_method, not_impersonating, machine_too_old, too_many_credential_values, limit_reached, terms_version_mismatch, no_project, last_owner, organization_not_empty, project_has_sessions, already_member, invite_pending, idempotency_in_progressThe current state does not allow it, or a request with this Idempotency-Key is still being answered.
502 Bad Gatewaymachine_error, machine_unreachable, page_unreachableThe session machine failed or could not be reached, or, for fetch, screenshot, pdf and extract, the page could not be loaded.
Error body
{  "error": {    "code": "not_found",    "message": "session not found",    "requestId": "req_4fJx0aQm2Lk9Pz7N"  }}

Use with the browser

Read what the shell wrote after it worked on a download. See Browser, shell and files together.

curl -G https://api.boxline.dev/v1/sessions/$SESSION_ID/files/wait \  -H "x-api-key: $BOXLINE_API_KEY" \  --data-urlencode "pattern=downloads/*.csv"curl -X POST https://api.boxline.dev/v1/sessions/$SESSION_ID/shell/exec \  -H "x-api-key: $BOXLINE_API_KEY" \  -H "content-type: application/json" \  -d @- <<'JSON'{"command": "mkdir -p output && python3 -c \"import pandas as pd; print(pd.read_csv('downloads/report.csv')['revenue'].sum())\" > output/total.txt"}JSONcurl -G https://api.boxline.dev/v1/sessions/$SESSION_ID/files \  -H "x-api-key: $BOXLINE_API_KEY" \  --data-urlencode "path=output/total.txt"

Learn more

These docs describe a beta API. Endpoints, fields and SDK methods may change before general availability; breaking changes will be listed in the changelog.