Bring Your Own Infrastructure
Automatically provision and tear down remote workspaces for each task using your own infrastructure
Plug in custom shell scripts that create and destroy remote environments on demand. When a developer creates a task, Krabby runs your provision script, connects the terminal via SSH, and runs coding agents inside the workspace. When the task is deleted, Krabby runs your teardown script to clean up.
This works with any infrastructure backend: cloud VMs, Kubernetes pods, container-based dev environments, or internal workspace platforms. You just provide the scripts.


How It Works
- Developer creates a task with "Remote workspace" enabled
- Krabby runs your provision script as a child process
- Script progress (stderr) streams live in the UI
- Script outputs JSON (stdout) with SSH connection details
- Krabby connects the terminal to the workspace via SSH
- Coding agents run inside the remote workspace
- When the task is deleted, Krabby runs your teardown script
Compared to Remote Projects
| Remote Projects | Workspace Provider | |
|---|---|---|
| Lifecycle | Persistent server, shared across tasks | Per-task, provisioned on demand |
| Setup | Manual connection in Settings | Automated via scripts |
| Infra management | You manage the server | Scripts handle create/destroy |
| Use case | Dedicated dev server | Ephemeral, isolated workspaces |
Both features share the same remote capabilities once connected: terminal access, coding agents, Git operations, and file browsing all work identically.
Setup
Step 1: Create Your Scripts
Create two shell scripts in your project root (or anywhere accessible from the project directory).
Provision Script
The provision script creates a workspace and outputs SSH connection details as JSON to stdout. All log messages must go to stderr.
Environment variables provided by Krabby:
| Variable | Description |
|---|---|
KRABBY_TASK_ID | Unique identifier for the task |
KRABBY_REPO_URL | Repository URL (e.g., git@github.com:org/repo.git) |
KRABBY_BRANCH | Branch name for this task |
KRABBY_BASE_REF | Base branch (e.g., main) |
Required output (JSON to stdout):
{
"host": "workspace-hostname-or-ip",
"id": "optional-external-id",
"port": 22,
"username": "dev",
"worktreePath": "/path/to/repo/on/workspace"
}| Field | Required | Description |
|---|---|---|
host | Yes | Hostname, IP address, or SSH config alias |
id | No | External identifier (passed to teardown as KRABBY_INSTANCE_ID) |
port | No | SSH port (default: 22) |
username | No | SSH username (default: current user) |
worktreePath | No | Path to the repository on the workspace |
Example provision script:
#!/bin/bash
set -euo pipefail
echo "[$(date)] Creating workspace for $KRABBY_BRANCH..." >&2
# Replace this section with your infrastructure commands
WORKSPACE_ID="ws-$(date +%s)"
HOST="dev-${WORKSPACE_ID}.internal.example.com"
echo "[$(date)] Provisioning VM..." >&2
# your-cli create-workspace --id "$WORKSPACE_ID" \
# --repo "$KRABBY_REPO_URL" --branch "$KRABBY_BRANCH"
echo "[$(date)] Ready!" >&2
# Output JSON to stdout (this is what Krabby parses)
cat <<EOF
{
"id": "$WORKSPACE_ID",
"host": "$HOST",
"port": 22,
"username": "dev",
"worktreePath": "/workspace/repo"
}
EOFImportant rules:
- All log output must go to stderr (
>&2) — Krabby streams these lines live in the UI - Only the JSON object goes to stdout — this is parsed for connection details
- Exit with code 0 on success, non-zero on failure
- Timeout: 5 minutes
Teardown Script
The teardown script destroys the workspace when the task is deleted.
Environment variables provided by Krabby:
| Variable | Description |
|---|---|
KRABBY_INSTANCE_ID | The id from your provision output (or host if no id was provided) |
KRABBY_TASK_ID | The task identifier (same value passed to the provision script) |
Example teardown script:
#!/bin/bash
set -euo pipefail
echo "[$(date)] Destroying workspace $KRABBY_INSTANCE_ID..." >&2
# your-cli delete-workspace "$KRABBY_INSTANCE_ID"
echo "[$(date)] Done." >&2Make both scripts executable:
chmod +x provision.sh teardown.shStep 2: Configure .krabby.json
Add the workspace provider configuration to .krabby.json in your project root:
{
"workspaceProvider": {
"type": "script",
"provisionCommand": "./provision.sh",
"terminateCommand": "./teardown.sh"
}
}Alternatively, configure via the Krabby UI:
- Open your project
- Click the gear icon (Project Settings)
- Scroll to the Workspace Provider section
- Enter your provision and terminate commands
- Save
Step 3: Create a Task
- Click New Task
- In the task creation dialog, expand Advanced Settings
- Check "Remote workspace (provision via script)"
- Create the task
Krabby will:
- Show a provisioning overlay with live progress from your script's stderr
- Parse the JSON output to get connection details
- Connect the terminal to the workspace via SSH
- Start your coding agent inside the workspace
Workspace Requirements
For the best experience, ensure your provisioned workspaces have these tools installed:
Required
- SSH server — Krabby connects via your system's
sshcommand - Git — For repository operations, configured with
user.nameanduser.email - A coding agent — At least one CLI agent (Claude Code, Codex, etc.)
Recommended
- GitHub CLI (
gh) — For PR creation and GitHub operations from the Krabby UI - tmux — Krabby automatically uses tmux for workspace sessions to preserve state across reconnects
GitHub Access (for push/pull)
If your workflow involves pushing code, configure SSH access to GitHub on the workspace:
ssh-keygen -t ed25519 -C "workspace" -f ~/.ssh/id_github -N ""
# Add ~/.ssh/id_github.pub to GitHub (deploy key or user key)
git config --global core.sshCommand "ssh -i /home/dev/.ssh/id_github"
ssh-keyscan -t ed25519 github.com >> ~/.ssh/known_hosts 2>/dev/nullSSH Authentication
Krabby connects to workspaces using your local system's ssh command, which means:
- SSH config aliases work — Your provision script can return an SSH config
Hostalias as thehostfield - SSH agent works — Keys in your local SSH agent (including macOS Keychain) are available
- ~/.ssh/config works — ProxyJump, custom ports, identity files, and other SSH config directives are respected
No additional SSH configuration is needed in Krabby itself.
Task Lifecycle
Creating a Task
When you create a task with remote workspace enabled:
- Provision script runs (progress streams in the UI)
- On success: SSH connection is established, agent starts in the workspace
- On failure: error is shown in the UI with a retry option
Deleting a Task
When you delete a workspace-backed task:
- Teardown script runs with
KRABBY_INSTANCE_ID - On success: workspace is destroyed, database is cleaned up
- On failure: instance is marked as error, task is kept for retry
App Restart
If Krabby is restarted while workspaces are active:
- Provisioning instances are marked as error (the child process is gone)
- Ready instances remain — the SSH connection is re-established when you open the task
Troubleshooting
Provision Script Fails
Symptoms: Error overlay with script output
Solutions:
- Check the error message in the overlay — it includes the last 500 chars of stderr
- Run the script manually to debug:
KRABBY_TASK_ID=test KRABBY_REPO_URL=git@github.com:org/repo.git \ KRABBY_BRANCH=test-branch KRABBY_BASE_REF=main \ ./provision.sh - Verify the JSON output is valid: pipe stdout through
jq - Ensure log output goes to stderr, not stdout
SSH Connection Fails After Provisioning
Symptoms: Terminal shows SSH error after provision succeeds
Solutions:
- Verify you can SSH manually:
ssh <host>(using the host from your script output) - Check your
~/.ssh/configfor the host - Verify your SSH agent has the right key loaded:
ssh-add -l - If using an SSH config alias, ensure the alias is configured on the machine running Krabby
Script Times Out
Provision scripts have a 5-minute timeout and teardown scripts have a 2-minute timeout. If your infrastructure takes longer, optimize the provisioning pipeline or pre-warm environments.
"Invalid JSON" Error
Symptoms: "Provision script output is not valid JSON"
Solutions:
- Ensure only JSON is printed to stdout — all log messages must use
>&2 - Check for stray
echoorprintfstatements without>&2 - Validate your output:
./provision.sh 2>/dev/null | jq .
Script Contract Reference
Provision Script
| Aspect | Details |
|---|---|
| Execution | bash -c <provisionCommand> |
| Working directory | Project root |
| Env vars | KRABBY_TASK_ID, KRABBY_REPO_URL, KRABBY_BRANCH, KRABBY_BASE_REF |
| Stdout | JSON object with at least host field |
| Stderr | Log lines (streamed to UI) |
| Exit code | 0 = success, non-zero = failure |
| Timeout | 5 minutes |
Teardown Script
| Aspect | Details |
|---|---|
| Execution | bash -c <terminateCommand> |
| Working directory | Project root |
| Env vars | KRABBY_INSTANCE_ID, KRABBY_TASK_ID |
| Stdout | (ignored) |
| Stderr | Log lines |
| Exit code | 0 = success, non-zero = failure |
| Timeout | 2 minutes |