Skip to content

feat: add team production remote sandbox baseline - #123

Merged
delete-cloud merged 10 commits into
mainfrom
feat/adr-0020-team-production-baseline
May 10, 2026
Merged

delete-cloud merged 10 commits into
mainfrom
feat/adr-0020-team-production-baseline

Conversation

@delete-cloud

@delete-cloud delete-cloud commented May 10, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • add ADR-0020 for the team production Docker remote workspace baseline
  • add explicit serve --config loading plus production-mode fail-fast validation and bearer token env support
  • add Docker workspace active quota and stale workspace GC with startup/periodic lifecycle wiring
  • add production deployment docs and clarify remote one-shot/snapshot UX wording

Non-goals

  • no live sync, patch export, full persistent attach TUI, Kubernetes/SSH/VM/microVM providers, multi-tenant identity, egress allowlists, or Codex/microVM isolation claims

Verification

  • uv run pytest tests/ui/test_http_server.py -k "production or explicit_server_config or cloud_workspace_gc" -v
  • uv run pytest tests/coding_agent/environment/test_docker_workspace_provider.py -k "quota or gc or provision" -v
  • uv run pytest tests/cli/test_remote_client.py -q
  • uv run pytest tests/coding_agent/environment/ tests/ui/test_execution_binding.py tests/ui/test_http_server.py tests/ui/test_http_server_workspace_transfer.py tests/ui/test_session_manager_runtime.py -k "cloud or workspace or binding or production or gc or quota" -q
  • uv run basedpyright --level error src/coding_agent/ui/http_server.py src/coding_agent/ui/auth.py src/coding_agent/environment/workspace_provider.py src/coding_agent/environment/docker_workspace_provider.py tests/ui/test_http_server.py tests/ui/test_security.py tests/coding_agent/environment/test_docker_workspace_provider.py tests/cli/test_remote_client.py
  • uv run ruff format src/coding_agent/main.py src/coding_agent/ui/auth.py src/coding_agent/ui/http_server.py src/coding_agent/environment/init.py src/coding_agent/environment/workspace_provider.py src/coding_agent/environment/docker_workspace_provider.py tests/ui/test_http_server.py tests/ui/test_security.py tests/coding_agent/environment/test_docker_workspace_provider.py tests/cli/test_remote_client.py --check
  • git diff --check

Summary by CodeRabbit

Release Notes

  • New Features

    • Added --config command-line option to explicitly specify a custom server configuration file.
    • Enhanced API authentication to support Bearer token credentials.
    • Introduced cloud workspace quota enforcement and automated cleanup of stale workspaces.
    • Production startup now validates security and safety configurations.
  • Documentation

    • Added production deployment baseline guide for Docker-based remote workspaces with recommended security settings.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 10, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Rate limit exceeded

@delete-cloud has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 42 minutes and 34 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 82de3385-09d4-4631-b323-1eb66aa74d7a

📥 Commits

Reviewing files that changed from the base of the PR and between 146c0f6 and 92fe14a.

📒 Files selected for processing (9)
  • coding-agent/docs/adr/0020-team-production-docker-remote-sandbox-baseline.md
  • coding-agent/src/coding_agent/__main__.py
  • coding-agent/src/coding_agent/environment/docker_workspace_provider.py
  • coding-agent/src/coding_agent/ui/auth.py
  • coding-agent/src/coding_agent/ui/http_server.py
  • coding-agent/tests/cli/test_remote_client.py
  • coding-agent/tests/coding_agent/environment/test_docker_workspace_provider.py
  • coding-agent/tests/ui/test_http_server.py
  • coding-agent/tests/ui/test_security.py
📝 Walkthrough

Walkthrough

This PR implements ADR-0020's production baseline for Docker remote workspaces. It adds explicit server.production mode with fail-fast validation, bearer-token authentication from server config, Docker workspace quota enforcement and periodic garbage collection, CLI --config argument support, and comprehensive test coverage. The changes enable safe team deployments with required security/safety constraints.

Changes

Production Docker Remote Sandbox Baseline

Layer / File(s) Summary
Design & Contract
coding-agent/docs/adr/0020-team-production-docker-remote-sandbox-baseline.md, coding-agent/docs/remote-sandbox-production.md
ADR-0020 and production baseline guide define explicit server.production mode with fail-fast startup validation, bearer-token auth, Docker workspace quota/GC, observability scope, and snapshot transfer semantics; includes implementation plan and acceptance criteria.
Workspace Provider Protocol
coding-agent/src/coding_agent/environment/workspace_provider.py, coding-agent/src/coding_agent/environment/__init__.py
WorkspaceProvider protocol adds cleanup_stale_cloud_workspaces(config) -> int method; new cleanup_stale_cloud_workspaces_from_config helper function re-exported from environment module.
Docker Provider Config
coding-agent/src/coding_agent/environment/docker_workspace_provider.py
_DockerWorkspaceProviderConfig adds optional max_active_workspaces and max_workspace_age_seconds fields; config parsing supports new settings.
Docker Provider Quota & GC
coding-agent/src/coding_agent/environment/docker_workspace_provider.py
DockerWorkspaceProvider enforces active-workspace quota during provisioning; cleanup_stale_cloud_workspaces removes stale Docker containers and workspace directories by mtime cutoff.
Server Config Loading
coding-agent/src/coding_agent/ui/http_server.py
http_server adds CODING_AGENT_SERVER_CONFIG environment variable support with fallback to agent.toml; introduces config section loaders (_load_server_config, _load_cloud_workspace_config) and production validation (_validate_production_config).
Bearer Token Authentication
coding-agent/src/coding_agent/ui/auth.py
verify_api_key now accepts X-API-Key or Authorization: Bearer headers; resolves bearer token from server config via bearer_token_env or direct bearer_token when settings.http_api_key unavailable; raises 401 for missing/invalid tokens.
Server Lifespan Integration
coding-agent/src/coding_agent/ui/http_server.py
FastAPI lifespan handler adds optional startup cloud-workspace cleanup, logs development-mode warning when production != true, and starts periodic stale-workspace GC task with interval from config.
CLI Serve Command
coding-agent/src/coding_agent/__main__.py
serve command accepts optional --config argument; exports resolved config path to CODING_AGENT_SERVER_CONFIG environment variable before starting server.
CLI Remote Commands
coding-agent/src/coding_agent/__main__.py
remote repl command messaging clarified as "one-shot"; snapshot download message describes overwriting workspace while preserving .git; cleanup error handling consolidated.
Docker Provider Tests
coding-agent/tests/coding_agent/environment/test_docker_workspace_provider.py
New tests verify quota enforcement rejects provisioning when limit reached, quota ignores unowned workspace directories, and GC removes only stale owned workspaces while preserving fresh ones.
Server Config & Auth Tests
coding-agent/tests/ui/test_http_server.py, coding-agent/tests/ui/test_security.py
New tests verify server config loading from CODING_AGENT_SERVER_CONFIG, production validation acceptance/rejection of unsafe configs, development-mode warning logging, periodic GC scheduling, and bearer-token authentication from server config environment variables.
CLI Tests
coding-agent/tests/cli/test_remote_client.py
New tests verify serve --config sets environment variable and help text; existing assertions updated for one-shot session language and snapshot preservation; test formatting refactored for readability.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 The production warren is now secure,
With quotas enforced and cleanup pure,
Bearer tokens guard the remote door,
One-shot sessions—no local sync anymore!
Docker's sandbox holds the line,
As baselines in code now align. ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 7.14% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title clearly and concisely summarizes the main change: adding a production baseline for remote Docker workspaces, which aligns with the ADR-0020 and production validation implementation across the entire changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/adr-0020-team-production-baseline

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@coding-agent/src/coding_agent/environment/docker_workspace_provider.py`:
- Around line 363-364: The quota check is racy: calls to
_enforce_active_workspace_quota(provider_config) and the subsequent creation of
workspace_id must be made atomic to prevent concurrent creators from exceeding
max_active_workspaces; wrap the enforcement+reservation in a lock or atomic
reservation step (e.g., acquire a provider-level mutex or create an atomic
marker file under the workspace root) so that once
_enforce_active_workspace_quota passes a caller immediately reserves the slot
before releasing the lock and then proceeds to create the workspace directory;
update the code paths around _enforce_active_workspace_quota, workspace_id
generation, and the workspace directory creation (same pattern around the code
at lines referenced 612-623) to use this lock-or-reserve mechanism.
- Around line 433-437: The current cleanup_stale_cloud_workspaces() and
_cleanup_stale_docker_workspaces() flow deletes workspaces purely by age
(provider_config.max_workspace_age_seconds) which can remove containers still in
use; modify the logic to skip any workspace that has an active session/lease
binding before deleting: in cleanup_stale_cloud_workspaces() fetch the list of
active sessions or leases (or call a new helper like
is_workspace_active(workspace_id) or get_active_session_for_workspace) and pass
that predicate into _cleanup_stale_docker_workspaces(), or enhance
_cleanup_stale_docker_workspaces() to check session ownership/lease state for
each candidate workspace_id and skip deletion if active; ensure
provider_config.max_workspace_age_seconds still gates candidates but never
deletes workspaces with an active session.

In `@coding-agent/src/coding_agent/ui/auth.py`:
- Around line 20-29: The current _server_config_bearer_token swallows
ConfigError/OSError and returns None which upstream auth code (the auth
enable/disable path that calls _server_config_bearer_token) interprets as "no
token" and disables auth; change this to fail-closed by not swallowing the
exceptions: inside _server_config_bearer_token, on ConfigError/OSError log a
clear error (include _SERVER_CONFIG_ENV and configured_path) and re-raise the
exception (or return an explicit failure sentinel that the authentication
initialization treats as denial rather than disabling auth); also update the
caller that currently treats None as "disable auth" to treat an exception or the
failure sentinel as "deny all" so unreadable/malformed configured auth sources
do not permit anonymous access (refer to load_agent_toml and the auth
enable/disable logic that consumes _server_config_bearer_token).
- Around line 69-76: The code currently sets provided_token to X-API-Key
unconditionally, rejecting a valid Bearer when both headers are present; update
the assignment so that either credential is accepted by preferring a non-empty
bearer token first and falling back to X-API-Key. Specifically, replace the
provided_token assignment with logic that uses bearer_token if it is truthy,
otherwise uses x_api_key (with the existing isinstance(x_api_key, str) check);
keep the earlier bearer_token extraction logic (authorization, scheme, value)
and the subsequent null check unchanged.

In `@coding-agent/src/coding_agent/ui/http_server.py`:
- Around line 95-113: The code in _load_agent_config_section silently returns {}
on ConfigError/OSError even when an explicit config was requested; change the
except block to fail fast if the config path was provided via the
CODING_AGENT_SERVER_CONFIG env var (or otherwise explicitly set by
_server_config_path). In practice, inside _load_agent_config_section, detect
whether the config_path came from the explicit env var
(CODING_AGENT_SERVER_CONFIG) and if so re-raise the caught exception (or raise a
new descriptive exception) instead of logging and returning {}; otherwise
preserve the current fallback logging and return {}. Ensure this touches the
exception handling around load_agent_toml and keeps behavior for
implicit/missing default config while forcing failure for explicit server
configs so callers like _validate_production_config run.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 7dd0ea31-2a06-4368-91d2-e807a26c3954

📥 Commits

Reviewing files that changed from the base of the PR and between 7a4e7ed and 146c0f6.

📒 Files selected for processing (12)
  • coding-agent/docs/adr/0020-team-production-docker-remote-sandbox-baseline.md
  • coding-agent/docs/remote-sandbox-production.md
  • coding-agent/src/coding_agent/__main__.py
  • coding-agent/src/coding_agent/environment/__init__.py
  • coding-agent/src/coding_agent/environment/docker_workspace_provider.py
  • coding-agent/src/coding_agent/environment/workspace_provider.py
  • coding-agent/src/coding_agent/ui/auth.py
  • coding-agent/src/coding_agent/ui/http_server.py
  • coding-agent/tests/cli/test_remote_client.py
  • coding-agent/tests/coding_agent/environment/test_docker_workspace_provider.py
  • coding-agent/tests/ui/test_http_server.py
  • coding-agent/tests/ui/test_security.py

Comment thread coding-agent/src/coding_agent/environment/docker_workspace_provider.py Outdated
Comment thread coding-agent/src/coding_agent/environment/docker_workspace_provider.py Outdated
Comment thread coding-agent/src/coding_agent/ui/auth.py Outdated
Comment thread coding-agent/src/coding_agent/ui/auth.py Outdated
Comment thread coding-agent/src/coding_agent/ui/http_server.py
@delete-cloud
delete-cloud merged commit 988bd4e into main May 10, 2026
1 check passed
@delete-cloud
delete-cloud deleted the feat/adr-0020-team-production-baseline branch May 10, 2026 03:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant