PHPSandbox CLI
Create sandboxes, run commands, work with files and Git, and manage the sandbox lifecycle from your terminal. The CLI uses the PHPSandbox SDK and the platform API, with progress output for provisioning and restoration, interactive shells, and JSON output for scripts.
Install
With Node.js 22 or newer:
npm install --global @phpsandbox/cli@latest
psb --version
Bun is not required to use the npm package. Keep npm's optional dependencies enabled: they provide the executable for your platform.
For an executable with no Node.js or Bun requirement, download a binary and its .sha256 file from GitHub Releases. Available targets are macOS arm64/x64, Linux arm64/x64 with glibc or musl, and Windows x64.
On macOS or Linux, verify the checksum, make the file executable, rename it to psb, and place it in a directory on your PATH. For example, after downloading the macOS arm64 assets:
shasum -a 256 -c psb-darwin-arm64.sha256
chmod +x psb-darwin-arm64
mkdir -p "$HOME/.local/bin"
mv psb-darwin-arm64 "$HOME/.local/bin/psb"
export PATH="$HOME/.local/bin:$PATH"
On Windows, download psb-windows-x64.exe, compare Get-FileHash -Algorithm SHA256 with its checksum file, rename it to psb.exe, and add its directory to your user Path.
psb is the command name. The npm package remains @phpsandbox/cli; npm also installs phpsandbox as a compatibility alias. Existing environment variables and .phpsandbox.json files continue to work.
Project features use an explicit product workspace ID: psb feedback list --project PROJECT_ID, psb payments show --project PROJECT_ID, and psb publication status --project PROJECT_ID. Compute commands continue to use --sandbox or the selected sandbox.
Your first sandbox
Run psb auth login to sign in through your browser. Compare the code, select one or more subscribed Helfer organizations, and approve. The CLI stores a separate key for each in your operating system credential store.
psb auth login
psb whoami
psb create --template standard --name first-sandbox
psb status
psb exec -- php -v
psb exec -- php -r 'echo "Hello from PHPSandbox\n";'
psb files list
psb open
Use psb auth use ORGANIZATION to switch saved organizations, or add --org ORGANIZATION to a single command. Use psb auth login --api-key to paste an existing key, or --token-stdin for scripts.
create waits for provisioning and selects the new sandbox. open opens its preview; use open --print to print the URL. Run psb shell for an interactive shell.
When you finish:
psb stop # Keep the notebook; stop its runtime
psb ready # Start or restore it and wait until ready
psb delete # Permanently delete after confirmation
For an existing sandbox, run psb use SANDBOX_ID in your project directory. This writes .phpsandbox.json with the sandbox ID and API endpoint. To target one command explicitly, use --sandbox SANDBOX_ID.
Explore
psb --help
psb files --help
psb git checkpoint --help
psb list --json
- Command reference: all commands, arguments, flags, and defaults, generated from the CLI.
- Authentication, configuration, and CI: credentials, sandbox selection, output, automation, and troubleshooting.
- Workflow guide: common tasks for running commands, transferring files, Git, and secrets.
- Development guide: build, install locally, test against an API, regenerate documentation, and release.
Scripting
Provide your API key as PHPSANDBOX_TOKEN using your CI secret store. Add --json to commands that return structured data, and --yes to confirmed destructive operations. Remote exec commands preserve their exit code.
psb exec --sandbox SANDBOX_ID --json -- php -v
psb delete SANDBOX_ID --yes --json
Progress goes to stderr; JSON results go to stdout. Commands that follow logs or other streams emit JSON Lines with --json.
Publishing
Inspect your app and the destination before publishing:
psb publication readiness
psb publication catalog ssh-server --server SERVER_ID
psb publication catalog laravel-cloud
psb publication catalog cloudflare-containers
psb publication plan publish.json
psb publish publish.json
Use your connected server or provider account. The catalog returns the same resource choices as the publishing panel. Plans show missing settings and resource choices without creating resources. Publishing asks for confirmation; use --yes for scripts. For repository-based publishing, workspace changes are committed and pushed before deployment. Provider resources may incur charges.
For example, an SSH publishing file can create a separate production MySQL database:
{
"slug": "my-app",
"provider": { "name": "ssh-server", "serverId": "SERVER_ID" },
"resources": {
"database": { "mode": "create", "type": "mysql", "version": "8.4" },
"cache": { "mode": "none" },
"storage": { "mode": "none" },
"worker": { "mode": "none" },
"scheduler": { "mode": "none" }
}
}
For Laravel Cloud, use {"name":"laravel-cloud","region":"eu-central-1","setup":{"repositoryAccessConfirmed":true}} as the provider. Choose resource types, sizes and configuration from its catalog. For Cloudflare Containers, use {"name":"cloudflare-containers","accountId":"ACCOUNT_ID"}. Cloudflare does not provision databases, caches or file storage through this integration. Declaring a resource external only records your choice; configure its connection separately in Production secrets.
psb publish --yes # Publish changes with the existing setup
psb publication status --json
psb publication resources --json
psb publication build-logs
psb publication delete # Unpublish and retain resources
psb publication delete --delete-resources # Remove app-owned resources and their data
Publishing follows progress and build logs by default. --no-wait returns after the publishing stream attaches; deployment continues on the server. Removing resources permanently deletes their data. Resources reused from elsewhere remain managed separately.
Live publishing tests
bun run test:publications exercises all three providers through the standalone executable: plan, publish, HTTP response, republish, unpublish and resource cleanup. It requires PHPSANDBOX_API_URL, PHPSANDBOX_TOKEN, PHPSANDBOX_PUBLICATION_SOURCE (a disposable app fixture), and PHPSANDBOX_PUBLICATION_CONFIGS (a JSON object with a publishing configuration for each provider name). Laravel Cloud also needs PHPSANDBOX_PUBLICATION_GIT_TARGET, the JSON Git target for a disposable repository and existing branch, including its author. Publishing can commit and push to that branch; do not use a production repository. Each test forks the source, attaches its existing provider connections, and cleans up the fork and app-owned publication resources even after a failure.
License
MIT.
Reviewed application publishing
Use application plan to prepare a server-owned review. It never builds or creates resources. The returned review includes blockers, the bound publication identity, resolved destination, required production settings and source snapshot. The platform determines supported choices; use publication catalog and publication resources for discovery.
psb application plan --provider ssh-server --server SERVER_ID \
--component web --dockerfile Dockerfile --port 3333 --health-path / \
--database-resource create --database-type mysql --database-version 8.4 \
--cache-resource create --cache-type redis --cache-version 7
psb application publish REVIEW_ID --yes --wait
psb application status APPLICATION_ID
psb application retry APPLICATION_ID --yes --wait
Only confirm a ready review after checking its choices. Confirmation sends its reference to Core; the CLI does not recreate source, resource or retry logic. A corrected review keeps the publication's identity and address. --wait observes platform state, and stopping the CLI leaves the platform operation running. A timeout requires inspection before retrying. application plan application.json or stdin supports multi-component plans; it cannot be mixed with native plan flags. Production settings use secrets set NAME --environment production, with values from stdin or a hidden prompt.
application delete APPLICATION_ID --yes unpublishes. Add --delete-resources only when you intend to remove owned resource data; Core enforces shared and external ownership.