Skip to content

Conversation

@fontanierh
Copy link
Contributor

@fontanierh fontanierh commented Jan 27, 2026

Description

Introduce the Northflank sandbox client for managing isolated Linux containers via the Northflank API.

Two-class design:

  • NorthflankSandboxClient - Factory for creating and attaching to sandboxes
  • Sandbox - Attached instance with all operations

Factory methods:

  • create(apiToken, configOverrides?) - Create a client instance
  • createSandbox(serviceName, metadata?) - Create a new sandbox with persistent volume
  • attach(info) - Reconnect to an existing sandbox

Sandbox operations:

  • exec(command) - Run bash commands, returns stdout/stderr/exitCode
  • writeFile(path, content) - Write files to the sandbox
  • readFile(path) - Read files from the sandbox
  • pause() / resume() - Pause/resume to save costs (idempotent)
  • destroy() - Delete sandbox and volume (idempotent, 404 = success)

Error handling:

  • Result<T, SandboxError> for recoverable errors (name collision, timeout)
  • Throws for infrastructure failures (API errors, deployment failures)

Configuration: Compute plans, spot node scheduling, timeouts, persistent volumes.

This is the foundation for sandbox MCP server tools.

Tests

  • Type-check passes
  • Manual testing against Northflank API

Risk

Low - New module with no integration points yet.

Deploy Plan

Standard deploy. Not used until sandbox MCP server tools are implemented.

@vercel
Copy link

vercel bot commented Jan 27, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

2 Skipped Deployments
Project Deployment Review Updated (UTC)
playground Ignored Ignored Preview Jan 28, 2026 0:55am
storybook Ignored Ignored Preview Jan 28, 2026 0:55am

Request Review

@fontanierh fontanierh force-pushed the northflank-client branch 4 times, most recently from 77f3253 to a688ab7 Compare January 27, 2026 18:13
@fontanierh fontanierh force-pushed the northflank-client branch 10 times, most recently from 3daa9bb to f9eba88 Compare January 27, 2026 22:43
@fontanierh fontanierh force-pushed the northflank-client branch 8 times, most recently from 64f26b9 to b0b4d69 Compare January 27, 2026 22:57
@fontanierh fontanierh force-pushed the northflank-client branch 4 times, most recently from e1670e2 to 5c4eb8a Compare January 27, 2026 23:09
Adds a client for managing sandboxes via the Northflank API:
- NorthflankSandboxClient with async factory pattern
- Methods: createSandbox, attach, exec, writeFile, readFile, destroy
- Config getters for API token and project ID
- Helper functions to check sandbox availability
- Clean up service/volume when sandbox readiness times out
- Check response.error in waitForReady() before accessing data
- Check errors in pause/resume/destroy and don't clear state on failure
- Rename sandboxConfig to config
- Extract resetState() and buildTags() helpers
- Remove redundant comments
- Condense object literals
METADATA_TAG_PREFIXES ensures adding a field to SandboxMetadata
forces updating the tag prefix mapping (TypeScript error otherwise).
- Wrap waitForReady() in try/catch to cleanup on throws, not just Err
- Check response.error in cleanupResources() (SDK doesn't throw on HTTP errors)
- Document error handling pattern: Err for recoverable, throw for infra failures
- NorthflankSandboxClient is now a factory with createSandbox() and attach()
- Sandbox class has all operations (exec, pause, resume, destroy, etc.)
- No more runtime requireServiceId() checks - type system enforces attachment
- createSandbox() returns Result<Sandbox, SandboxError>
- attach() returns Sandbox
- pause(): Check if already paused, return early if so
- resume(): Check if already running, return early if so
- destroy(): Treat 404 as success (already deleted)
- Replace getServiceStatus() -> isServicePaused() returning boolean
- Use response.data.servicePaused from Northflank SDK
- Simplify pause/resume idempotency checks
- Use normalizeError for consistent error handling (via code-simplifier)
- Use serviceParams getter to reduce duplication (via code-simplifier)
- Sandbox now uses this.info.projectId instead of config.projectId
  so attach() works correctly with persisted SandboxInfo
- waitForReady() now requires !servicePaused in addition to COMPLETED
  deployment status, preventing false positives when resuming
downloadServiceFileStream returns a completionPromise that indicates
whether the underlying cat command succeeded. Without checking it,
readFile could return empty/partial data on failure.
Call execServiceCommand directly with command array instead of going
through bash -c with string interpolation. Prevents unintended shell
expansion if remotePath contains metacharacters like $, backticks, etc.
- Use type-only import for Result
- Extract deleteServiceIfExists/deleteVolumeIfExists helpers
- Simplify buildTags with functional style
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.

2 participants