Skip to content

feat(remote-worker): sbx, a static Go client for one sandbox/v1 workspace - #727

Merged
pdettori merged 9 commits into
rossoctl:mainfrom
webchang:feat/sbx-static-go-client
Nov 12, 2026
Merged

pdettori merged 9 commits into
rossoctl:mainfrom
webchang:feat/sbx-static-go-client

Conversation

@webchang

Copy link
Copy Markdown
Member

Closes #726.

Adds remote-worker/cmd/sbx, a static Go client for one sandbox/v1 workspace: the Go twin of docs/api/examples/sbx.py, for agents in minimal containers.

Commits:

  1. sbx: sbx run and sbx put, with the same environment, exit codes, truncation notice, SBX_LOG line and PULL script as sbx.py. The token is read from a file, never argv. Ctrl-C/TERM aborts the Exec it started.
  2. SBX_TLS and SBX_CA_FILE: reach a TLS exec endpoint. The extra CA is added to the system roots, never replacing them, as sandbox-client's caBundle does. A misconfiguration is refused at start.
  3. SBX_DIAL_ADDR: connect to a caller-resolved ip:port, so per-call processes don't repeat the DNS lookup. TLS still verifies, and :authority still names, SBX_ADDR's host.
  4. A header comment: wording only.

Nothing else in the repository changes; the binary is inert unless invoked.

Tests: go vet ./cmd/sbx and go test ./cmd/sbx pass.

  • sbx_test.go drives the core against a scripted SandboxExecClient.
  • tls_test.go runs a real sandbox/v1 server over TLS on loopback with a self-issued CA: with the CA, without it (the dial is refused, never falling back to plaintext), a plaintext dial, and the dial address (passes for a certificate's name reached by IP, refused for another name).

Size: 4 files, +829 lines, about two thirds of them tests.

Assisted-By: Claude Code

…pace

The Go twin of docs/api/examples/sbx.py, for a coding agent whose shell may run only `sbx run` and
`sbx put`, in an image with no Python or grpcio: one static binary can be bind-mounted into any
container. The same environment (SBX_ADDR, SBX_SANDBOX_ID, SBX_WORKSPACE_KEY, SBX_TOKEN[_FILE],
SBX_TIMEOUT, SBX_LOG), the same exit codes (the command's own; 124 timeout; 125 sandbox failure; 137
for a signal), the same 8 MiB truncation notice, the same SBX_LOG line and PULL script, and req_id
below 2^53. No push: the workspace is seeded on the server side. Ctrl-C/TERM aborts the Exec it
started. Tests drive the core against a scripted SandboxExecClient. Inert unless invoked.

Signed-off-by: Rong Chang <[email protected]>
…_FILE)

sbx dialed plaintext only, so it could reach a local relay but not a TLS exec endpoint. With
SBX_TLS=1 it dials over TLS. The server is verified against the system roots plus SBX_CA_FILE's CA
when given (a sandbox token grant's execCa, for a self-issued certificate): the extra CA is added to
the roots, never replacing them, as sandbox-client's caBundle does. SBX_CA_FILE without SBX_TLS, a
bad SBX_TLS value and a file with no PEM are refused at start. Without SBX_TLS, nothing changes.

Tests (tls_test.go) run a real sandbox/v1 server over TLS on loopback with a self-issued CA:
- with the CA, the command runs through the client's own execOnce;
- without it, the dial is refused, never falling back to plaintext;
- a plaintext dial cannot reach the TLS server.
A deliberate break (the CA ignored) was caught.

Signed-off-by: Rong Chang <[email protected]>
…_ADDR)

Each sbx call is its own process, so each one looked up the exec endpoint's host again; behind a slow
resolver that cost about 20 s per command. With SBX_DIAL_ADDR the caller resolves once and sbx
connects to that ip:port, while TLS still verifies, and :authority still names, SBX_ADDR's host.
Unset, nothing changes.

Tests: a certificate issued to a name that does not resolve, reached by IP (passes); the same with
another name (refused); the setting's parsing.

Signed-off-by: Rong Chang <[email protected]>
@webchang
webchang force-pushed the feat/sbx-static-go-client branch from 647eb61 to 0b333ba Compare November 12, 2026 04:43

@clawgenti clawgenti left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Summary

A clean, dependency-light Go client: vet and gofmt are clean, and go test -race ./cmd/sbx passes on head. No must-fix issues. Two suggestions concern behaviour that differs from sbx.py, the client this one is described as the twin of: signal exit codes, and how a timeout is detected and reported. Both were confirmed with throwaway probe tests on head, which were deleted afterwards. There is also one nit on the environment defaults.

Author: webchang (MEMBER — maintainer)
Areas reviewed: Go (remote-worker/cmd/sbx), tests, security (TLS config, token handling)
Agent/IDE config (.claude/.vscode): none
Commits: 6 commits, all signed-off: yes
CI status: passing

Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).

Comment thread remote-worker/cmd/sbx/sbx.go Outdated
}
code = int(r.exitCode)
if code < 0 {
code = 128 + 9

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion — Signal exits are hard-coded to 137. sbx.py (which the header calls this file's twin) returns 128 - exit_code, so -15 (SIGTERM) gives 143 there. A probe on head with end(-15, false) returned 137 here, against 143 from sbx.py. An agent that branches on the exit code will see a different signal depending on which client it runs.

Suggested fix: code = 128 - code, plus a test case for a signal other than 9.

Comment thread remote-worker/cmd/sbx/sbx.go Outdated
var code int
if err != nil {
msg := err.Error()
if strings.Contains(msg, "timeout:") {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion — strings.Contains(msg, "timeout:") is broader than sbx.py's TIMEOUT_MESSAGE.fullmatch(r"timeout:\d+"), and it is checked against the whole error text, which includes rpc status messages. Two probes on head:

  • an ExecError vm boot failed: vsock dial timeout: 30s exits 124 with sbx: command timed out. That is a machinery failure, so it should be 125 with the real message.
  • chunk("partial") followed by timeout:600 exits 124 with stdout "". sbx.py returns Result(out, err, 124, timed_out=True) and writes the partial output.

Suggested fix: classify the timeout inside execOnce (an in-stream ExecError whose message fully matches ^timeout:\d+$), return the buffered output with it, and write that output in callID.

c.token = strings.TrimSpace(string(b))
}
switch v := getenv("SBX_TLS"); v {
case "", "0":

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit — SBX_TLS defaults to plaintext here, while sbx.py/Sandbox.from_env default to TLS (SBX_TLS "1"). This client also does not read SBX_TOKEN_CMD, which is what mocactl sbx env prints, so eval "$(mocactl sbx env <id>)"; sbx run … stops with "neither SBX_TOKEN nor SBX_TOKEN_FILE is set". The error is clear, but the usage text could say both differences outright, since it presents this as the Go twin.

A timeout is the worker's in-stream ExecError whose whole message is timeout:<n>, as sbx.py's
TIMEOUT_MESSAGE.fullmatch checks it, and the output so far is written before exit 124 ("command
timed out after N s"). Any other error, including a machinery message that mentions a timeout
("vsock dial timeout: 30s"), is a sandbox failure, 125. A command killed by signal n exits 128 + n
(143 for SIGTERM), not always 137. The usage text states the two differences from sbx.py: TLS only
with SBX_TLS=1, and no SBX_TOKEN_CMD. From review on rossoctl#727.

Signed-off-by: Rong Chang <[email protected]>
Assisted-By: Claude (Anthropic AI) <[email protected]>
@webchang

Copy link
Copy Markdown
Member Author

Thanks for the review. All three points are addressed in 3f162ec:

  • Signal exits: a command killed by signal n now exits 128 + n, as sbx.py does (-15 → 143). The test covers -9, -15 and -2.
  • Timeouts: a timeout is only the in-stream ExecError whose whole message is timeout:<n>, the same as sbx.py's fullmatch. The output so far is written before exit 124 ("command timed out after N s"). Any other error is 125, including a machinery message like vm boot failed: vsock dial timeout: 30s, which now has its own test case. Partial stdout on a timeout is tested too.
  • Defaults (nit): the usage text now states the two differences from sbx.py: plaintext unless SBX_TLS=1, and no SBX_TOKEN_CMD, so mocactl sbx env's exports alone aren't enough.

go vet and go test -race ./cmd/sbx pass.

Assisted-By: Claude Code

@clawgenti clawgenti left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Summary

The new commit 3f162ec fixes both suggestions from the previous review. A timeout is now detected only from the in-stream ExecError ^timeout:\d+$, and the partial output is written before exit 124. A machinery error such as vsock dial timeout: 30s is now exit 125. A signal exit is now 128 + n (143 for SIGTERM), which matches sbx.py. The usage text now states the two differences from sbx.py (plaintext unless SBX_TLS=1, no SBX_TOKEN_CMD), which resolves the earlier nit. On head, go vet, gofmt and go test -race ./cmd/sbx pass. No must-fix issues. One nit on SBX_TIMEOUT parsing, confirmed with a throwaway probe test that was deleted afterwards.

Author: webchang (MEMBER — maintainer)
Areas reviewed: Go (remote-worker/cmd/sbx), tests, security (TLS config, token handling)
Agent/IDE config (.claude/.vscode): none
Commits: 7 commits, all signed-off: yes
CI status: passing (deploy-scripts-bash32 still pending)

Generated by RepoMan github-pr-review@235a7f7 (https://github.com/rossoctl/agent-skills/blob/235a7f7620139ee3e4ab0872b8439591fe52e8c1/skills/github-pr-review/SKILL.md).

Comment thread remote-worker/cmd/sbx/sbx.go Outdated
}
if s := getenv("SBX_TIMEOUT"); s != "" {
var n uint32
if _, err := fmt.Sscanf(s, "%d", &n); err != nil || n == 0 {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit — fmt.Sscanf(s, "%d", &n) accepts a leading integer and ignores the rest. A probe on head showed that SBX_TIMEOUT=1e3 gives a 1 s timeout and SBX_TIMEOUT=10s gives 10, both with no error. sbx.py's int(os.environ["SBX_TIMEOUT"]) rejects both. Suggested fix: use strconv.ParseUint(s, 10, 32), which is as strict as the strconv.Atoi that #729 uses for SBX_BUSY_RETRY_S.

@ingpaolodettori-dev ingpaolodettori-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Summary

The new commit 3f162ec fixes all of clawgenti's earlier points. A timeout is now only the in-stream ExecError that fully matches ^timeout:\d+$, as in sbx.py's TIMEOUT_MESSAGE.fullmatch, and the partial output is written before exit 124. A machinery error such as vsock dial timeout: 30s now exits 125. A signal exit is 128 + n, and the tests cover -9, -15 and -2. The usage text now states the two differences from sbx.py. I found no must-fix issues. I add one suggestion: the Exec timeout is still not capped to the static token's lifetime, unlike sbx.py and sandbox-client. clawgenti's open SBX_TIMEOUT Sscanf nit still applies and is not repeated here.

Author: webchang (MEMBER — maintainer)
Areas reviewed: Go (remote-worker/cmd/sbx), tests, security (TLS, token handling)
Agent/IDE config (.claude/.vscode): none
Commits: 7 commits, all signed-off: yes
CI status: passing (all checks green)

ReqId: id,
Command: command,
Stdin: stdin,
TimeoutS: cfg.timeoutS,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion (carried from our unposted 9f39066 draft; unchanged at this head): timeout_s is sent as SBX_TIMEOUT (default 600) with no cap. sbx.py/Sandbox.exec caps it at the token's lifetime minus 60 s and prints sbx: timeout capped at …, and sandbox-client does the same (exec-conn.ts TOKEN_MARGIN_S). This client reads a static token from SBX_TOKEN/SBX_TOKEN_FILE and never refreshes it. With the control plane's default SH_SANDBOX_TOKEN_TTL_SECONDS=900, SBX_TIMEOUT=1200 outlives the token, and so does a 600 s command started on a token more than 5 min old. The relay then cancels the Exec (DEADLINE_EXCEEDED "sandbox token expired during the Exec"), and sbx reports a generic 125. Suggested fix: when the token is a readable JWT, cap timeout_s at exp - now - 60 as sbx.py does, and say so on stderr. At minimum, name the token-expiry case in the 125 message and add it to the usage text's list of differences from sbx.py.

…ng digits

configFrom parsed SBX_TIMEOUT with fmt.Sscanf("%d"), which stops at the first
non-digit: "1e3" became a 1 s timeout and "10s" a 10 s one, silently. Parse the
whole value with strconv.ParseUint (base 10, 32 bits) and refuse anything else,
or 0, with an error naming the variable; the client exits 2 for it, as for its
other bad configuration.

Signed-off-by: Rong Chang <[email protected]>
sbx.py's Sandbox.exec cuts timeout_s to the token's lifetime less 60 s, and
to what the token has left less 60 s (never below 1 s), and says so on
stderr; otherwise a long SBX_TIMEOUT outlives the token and the relay
cancels the Exec at its exp. The Go client reads a static token and never
refreshes it, so it needs the same rule.

When the token is a JWT, its iat and exp are read from the payload without
verifying (the relay verifies; the token is never printed) and the timeout
sent is capped by sbx.py's rule, with sbx.py's line:
"sbx: timeout capped at N s, the sandbox token's lifetime minus 60 s".
A token that is not a JWT, or has no exp, is not capped. A timed-out
command reports the capped timeout.

A DEADLINE_EXCEEDED that names the token expiring (or has no message: the
client sets no deadline of its own) now exits 125 with sbx.py's text, "...:
the command outlived its token and was cancelled; give it a shorter
timeout". The usage text says both.

Signed-off-by: Rong Chang <[email protected]>
@webchang

Copy link
Copy Markdown
Member Author

Thanks for both reviews. The two open points are addressed in two new commits:

  • SBX_TIMEOUT parsing (afc24db): the value is parsed with strconv.ParseUint(s, 10, 32), so 1e3, 10s, +5, 1.5 and padded values are refused with exit 2, as other bad settings are. TestTimeoutFromEnv covers these cases.
  • The token-lifetime cap (75216ec): as in sbx.py's _prepare, when the token is a readable JWT the timeout is cut to its lifetime (exp - iat) less 60 s, and then to what it has left less 60 s, never below 1 s. The token is read without verifying it and is never printed. When the cap applies, sbx prints sbx: timeout capped at N s, the sandbox token's lifetime minus 60 s to stderr. A token that is not a JWT, or has no exp, is not capped. A DEADLINE_EXCEEDED that names the token expiring now exits 125 with sbx.py's wording ("the command outlived its token and was cancelled; give it a shorter timeout"). The usage text covers both. These tests cover it: TestTimeoutCappedAtTheTokensLifetime (10 cases), TestCappedTimeoutIsTheOneReported and TestTokenExpiredDuringExec.

gofmt, go vet and go test -race ./cmd/sbx pass.

Assisted-By: Claude Code

@ingpaolodettori-dev ingpaolodettori-dev left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Follow-up on 3f162ec..75216ec. afc24db closes the SBX_TIMEOUT parsing nit (ParseUint on the whole value; 1e3/10s/ 5/+5/overflow refused, tested). 75216ec closes our token-lifetime suggestion: capTimeout matches sbx.py's Sandbox._prepare (exp-iat-60, then ceil(exp-now)-60, floor 1 s, no cap without a readable exp), prints the same capped line, and names a token-expiry DEADLINE_EXCEEDED in sbx.py's words with exit 125, never printing the token. No new issues.

The proto check is red at this head (step "Build and test remote-worker"). In an isolated run, gofmt/vet were clean and go test -race ./cmd/sbx passed 3/3. #729's head, which contains this commit, has proto green. It looks like a flake, so please re-run it before merging.

Author: webchang (MEMBER — maintainer)
Areas reviewed: Go (remote-worker/cmd/sbx), tests, security
Agent/IDE config (.claude/.vscode): none
Commits: 9 commits, all signed-off: yes
CI status: green except proto (likely flaky, re-run)

@pdettori
pdettori merged commit 529ff96 into rossoctl:main Nov 12, 2026
23 of 24 checks passed
webchang added a commit to webchang/moca that referenced this pull request Nov 16, 2026
Conflicts: the sbx Go client, its tests, build-snapshot.sh and test_sandbox_v1_client.py take
upstream's reviewed versions, a superset of webchang's (rossoctl#727, rossoctl#729, rossoctl#757, rossoctl#761, the build-snapshot
PRs). packages/sandbox-relay/src/main.ts keeps webchang's per-client tokens beside upstream's
set-mode tokens, and direct clients' Execs are normalized to per-exec like the harness's.
sbx.py keeps the per-client-token environment line.

Signed-off-by: Rong Chang <[email protected]>
@pdettori pdettori added this to the v0.11.0 milestone Nov 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-ai-review Request automated AI code review from clawgenti

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A static Go client for sandbox/v1, for agents in minimal containers

4 participants