Secure, Fast, and Extensible Sandbox runtime for AI agents.
fix(execd): keep reading session output past a line longer than 16 MiB
Maohao1acd2345f93f
diff --git a/components/execd/pkg/runtime/bash_session.go b/components/execd/pkg/runtime/bash_session.goindex 87204a934..da899c7c8 100644--- a/components/execd/pkg/runtime/bash_session.go+++ b/components/execd/pkg/runtime/bash_session.go@@ -353,7 +353,19 @@ func (s *bashSession) run(ctx context.Context, request *ExecuteCodeRequest) erroemit(fragment)}- scanErr := scanLineFragments(stdoutR, handleFragment)+ // carry holds the tail of an unfinished piece of a long line: the wrapper's+ // env-dump marker follows output that lacks a trailing newline on the same+ // line, so it can be split across two pieces. The scanner always passes+ // another fragment after an unfinished piece, so carry is never left over.+ var carry string+ scanErr := scanLineFragments(stdoutR, func(fragment string, complete bool) {+ fragment = carry + fragment+ carry = ""+ if !complete {+ fragment, carry = holdBackMarkerPrefix(fragment, envDumpStartMarker)+ }+ handleFragment(fragment)+ })if inEnv {flushEnvRecord()}@@ -388,16 +400,13 @@ func (s *bashSession) run(ctx context.Context, request *ExecuteCodeRequest) erroreturn reportRunResult(request, waitErr, exitCode, startAt)}-// maxScanLineBytes bounds the buffer for a single output fragment without a-// line ending, matching the former bufio.Scanner cap; exceeding it fails the-// run instead of buffering without limit.-const maxScanLineBytes = 16 * 1024 * 1024-// scanLineFragments reads r and calls onFragment for each fragment terminated// by \n or \r, passing the terminator through; a final unterminated fragment-// is flushed at EOF. Concatenating the fragments reproduces the exact byte-// stream, including blank lines and \r-only progress output.-func scanLineFragments(r io.Reader, onFragment func(string)) error {+// is flushed at EOF. A line longer than maxScanLineBytes is passed in pieces+// with complete=false for all but the last piece; pieces never split a UTF-8+// sequence. Concatenating the fragments reproduces the exact byte stream,+// including blank lines and \r-only progress output.+func scanLineFragments(r io.Reader, onFragment func(fragment string, complete bool)) error {buf := make([]byte, 64*1024)var pending []bytefor {@@ -406,15 +415,19 @@ func scanLineFragments(r io.Reader, onFragment func(string)) error {b := buf[i]pending = append(pending, b)if b == '\n' || b == '\r' {- onFragment(string(pending))+ onFragment(string(pending), true)pending = pending[:0]- } else if len(pending) >= maxScanLineBytes {- return fmt.Errorf("output line exceeds %d bytes", maxScanLineBytes)+ } else if len(pending) > maxScanLineBytes {+ // The byte just read stays pending, so the last piece is never+ // empty.+ cut := lastRuneBoundary(pending[:maxScanLineBytes])+ onFragment(string(pending[:cut]), false)+ pending = pending[:copy(pending, pending[cut:])]}}if readErr != nil {if len(pending) > 0 {- onFragment(string(pending))+ onFragment(string(pending), true)}if errors.Is(readErr, io.EOF) {return nildiff --git a/components/execd/pkg/runtime/bash_session_test.go b/components/execd/pkg/runtime/bash_session_test.goindex 17486f4c2..afd9dccb7 100644--- a/components/execd/pkg/runtime/bash_session_test.go+++ b/components/execd/pkg/runtime/bash_session_test.go@@ -950,18 +950,66 @@ func TestBashSession_FlushesBlankLineImmediately(t *testing.T) {// Output without any line ending must fail the run at the fragment cap// instead of buffering without limit, mirroring the former 16 MiB scanner cap.-func TestBashSession_OutputLineCapErrors(t *testing.T) {+// A line longer than maxScanLineBytes arrives in pieces, and the output after+// it is still read: a reader that stopped would leave the command blocked on a+// full pipe until the run timed out.+func TestBashSession_LineLongerThanMaxScanLine(t *testing.T) {requireBash(t)session := newBashSession("", nil)t.Cleanup(func() { _ = session.close() })require.NoError(t, session.start())- err := session.run(context.Background(), &ExecuteCodeRequest{- Code: `head -c 17000000 /dev/zero | tr '\0' 'x'`,+ const longLineBytes = maxScanLineBytes + 4*1024*1024+ var stdout strings.Builder+ start := time.Now()+ require.NoError(t, session.run(context.Background(), &ExecuteCodeRequest{+ Code: fmt.Sprintf(`head -c %d /dev/zero | tr '\0' 'x'; echo; seq 1 100000`, longLineBytes),Timeout: 30 * time.Second,- })- require.ErrorContains(t, err, "output line exceeds")+ Hooks: ExecuteResultHook{+ OnExecuteStdout: func(fragment string) { stdout.WriteString(fragment) },+ },+ }))+ require.Less(t, time.Since(start), 20*time.Second)++ var want strings.Builder+ want.WriteString(strings.Repeat("x", longLineBytes) + "\n")+ for i := 1; i <= 100000; i++ {+ fmt.Fprintf(&want, "%d\n", i)+ }+ require.True(t, stdout.String() == want.String(), "stdout has %d bytes, want %d", stdout.Len(), want.Len())+}++// Output without a trailing newline puts the env-dump marker on the same line.+// With this length the piece boundary falls inside the marker, which must+// still be recognized so the env dump is not sent as output.+func TestBashSession_EnvDumpMarkerSplitByLongLine(t *testing.T) {+ requireBash(t)++ session := newBashSession("", nil)+ t.Cleanup(func() { _ = session.close() })+ require.NoError(t, session.start())++ const outputBytes = maxScanLineBytes - 5+ var stdout strings.Builder+ require.NoError(t, session.run(context.Background(), &ExecuteCodeRequest{+ Code: fmt.Sprintf(`export SPLIT_MARKER_VAR=kept; head -c %d /dev/zero | tr '\0' 'x'`, outputBytes),+ Timeout: 30 * time.Second,+ Hooks: ExecuteResultHook{+ OnExecuteStdout: func(fragment string) { stdout.WriteString(fragment) },+ },+ }))+ require.True(t, stdout.String() == strings.Repeat("x", outputBytes), "stdout has %d bytes, want %d", stdout.Len(), outputBytes)++ var got strings.Builder+ require.NoError(t, session.run(context.Background(), &ExecuteCodeRequest{+ Code: `printf '%s' "$SPLIT_MARKER_VAR"`,+ Timeout: 5 * time.Second,+ Hooks: ExecuteResultHook{+ OnExecuteStdout: func(fragment string) { got.WriteString(fragment) },+ },+ }))+ require.Equal(t, "kept", got.String())}// Env values may carry a literal CR byte (dash quotes export -p values@@ -1094,3 +1142,41 @@ func TestBashSession_SignalKillEmitsError(t *testing.T) {require.NotNil(t, gotErr.ExitCode, "expected exit_code for a signal-killed shell")require.Equal(t, -1, *gotErr.ExitCode)}++func collectLineFragments(t *testing.T, input string) []outputPiece {+ t.Helper()+ var fragments []outputPiece+ err := scanLineFragments(strings.NewReader(input), func(fragment string, complete bool) {+ fragments = append(fragments, outputPiece{fragment, complete})+ })+ require.NoError(t, err)+ return fragments+}++func TestScanLineFragments_SplitsLongLine(t *testing.T) {+ long := strings.Repeat("a", maxScanLineBytes+10)+ fragments := collectLineFragments(t, long+"\nnext")+ require.Equal(t, []outputPiece{+ {long[:maxScanLineBytes], false},+ {long[maxScanLineBytes:] + "\n", true},+ {"next", true},+ }, fragments)+}++func TestScanLineFragments_LineOfExactlyMaxBytes(t *testing.T) {+ long := strings.Repeat("a", maxScanLineBytes)+ fragments := collectLineFragments(t, long+"\r\n")+ require.Equal(t, []outputPiece{+ {long + "\r", true},+ {"\n", true},+ }, fragments)+}++func TestScanLineFragments_DoesNotSplitRune(t *testing.T) {+ // The odd prefix puts the piece boundary inside a two-byte rune.+ long := "a" + strings.Repeat("é", maxScanLineBytes/2)+ fragments := collectLineFragments(t, long)+ require.Len(t, fragments, 2)+ require.Len(t, fragments[0].text, maxScanLineBytes-1)+ require.Equal(t, long, fragments[0].text+fragments[1].text)+}diff --git a/components/execd/pkg/runtime/isolated_session_ctrl.go b/components/execd/pkg/runtime/isolated_session_ctrl.goindex 6ce53e2a8..5d0974712 100644--- a/components/execd/pkg/runtime/isolated_session_ctrl.go+++ b/components/execd/pkg/runtime/isolated_session_ctrl.go@@ -17,7 +17,6 @@package runtimeimport (- "bufio""context""errors""fmt"@@ -708,37 +707,12 @@ func (r *IsolatedRunner) RunInIsolatedSession(ctx context.Context, id string, co// scanUntilMarker reads stdout lines until the end marker is found.// Returns the exit code from the marker line.func scanUntilMarker(ctx context.Context, stdout io.ReadCloser, runMarker string, onStdout StdoutCallback) (int, error) {- scanner := bufio.NewScanner(stdout)- scanner.Buffer(make([]byte, 0, 64*1024), 16*1024*1024)-- var exitCode int- markerSeen := false+ scanner := &runOutputScanner{marker: runMarker, onStdout: onStdout}+ var scanErr errorscanDone := make(chan struct{})go func() {defer close(scanDone)- for scanner.Scan() {- line := scanner.Text()- // The marker may appear mid-line if the previous command's- // output didn't end with a newline (e.g. cat of a file- // without trailing newline).- if idx := strings.Index(line, runMarker); idx >= 0 {- markerSeen = true- if idx > 0 && onStdout != nil {- onStdout(line[:idx])- }- markerPart := line[idx:]- parts := strings.Fields(markerPart)- if len(parts) >= 2 {- if code, convErr := strconv.Atoi(parts[1]); convErr == nil {- exitCode = code- }- }- return- }- if onStdout != nil {- onStdout(line)- }- }+ scanErr = scanOutputLines(stdout, scanner.onLine)}()select {@@ -750,13 +724,64 @@ func scanUntilMarker(ctx context.Context, stdout io.ReadCloser, runMarker stringreturn 0, ctx.Err()}- if err := scanner.Err(); err != nil {- return 0, fmt.Errorf("read stdout: %w", err)+ if scanErr != nil {+ return 0, fmt.Errorf("read stdout: %w", scanErr)}- if !markerSeen {+ if !scanner.markerSeen {return 1, fmt.Errorf("session process exited without end marker (process may have died or called exit)")}- return exitCode, nil+ return scanner.exitCode, nil+}++// runOutputScanner forwards a run's output lines and stops at the end marker+// line that follows them.+type runOutputScanner struct {+ marker string+ onStdout StdoutCallback++ // carry holds the end of an unfinished piece of a long line, joined with+ // the next piece: either a tail that may start a split marker, or the+ // marker whose exit code is still to come.+ carry string+ markerSeen bool+ exitCode int+}++// onLine handles one piece from scanOutputLines and reports whether to keep+// scanning.+func (s *runOutputScanner) onLine(line string, complete bool) bool {+ line = s.carry + line+ s.carry = ""+ // The marker may appear mid-line if the previous command's output didn't+ // end with a newline (e.g. cat of a file without trailing newline).+ if idx := strings.Index(line, s.marker); idx >= 0 {+ if idx > 0 {+ s.emit(line[:idx])+ }+ if !complete {+ s.carry = line[idx:]+ return true+ }+ s.markerSeen = true+ parts := strings.Fields(line[idx:])+ if len(parts) >= 2 {+ if code, err := strconv.Atoi(parts[1]); err == nil {+ s.exitCode = code+ }+ }+ return false+ }+ if !complete {+ line, s.carry = holdBackMarkerPrefix(line, s.marker)+ }+ s.emit(line)+ return true+}++func (s *runOutputScanner) emit(text string) {+ if s.onStdout != nil {+ s.onStdout(text)+ }}// DeleteIsolatedSession destroys the session.diff --git a/components/execd/pkg/runtime/isolated_session_test.go b/components/execd/pkg/runtime/isolated_session_test.goindex 76b974033..e9175d355 100644--- a/components/execd/pkg/runtime/isolated_session_test.go+++ b/components/execd/pkg/runtime/isolated_session_test.go@@ -19,6 +19,7 @@ package runtimeimport ("context""errors"+ "io""os""os/exec""path/filepath"@@ -809,3 +810,73 @@ func TestValidateBinds_SymlinkBypass(t *testing.T) {t.Errorf("expected existing-path rejection, got: %v", err)}}++func TestScanUntilMarker_LineLongerThanMaxScanLine(t *testing.T) {+ const marker = isolatedRunEndMarkerPrefix + "_test"+ // The output has no trailing newline, so the marker follows it on the+ // same line and arrives in the last piece.+ output := strings.Repeat("a", maxScanLineBytes+100*1024)+ input := output + marker + " 7\nnext run output\n"++ var stdout []string+ exitCode, err := scanUntilMarker(context.Background(), io.NopCloser(strings.NewReader(input)), marker, func(text string) {+ stdout = append(stdout, text)+ })+ if err != nil {+ t.Fatalf("scanUntilMarker: %v", err)+ }+ if exitCode != 7 {+ t.Fatalf("exit code = %d, want 7", exitCode)+ }+ if got := strings.Join(stdout, ""); got != output {+ t.Fatalf("stdout has %d bytes, want the %d output bytes before the marker", len(got), len(output))+ }+}++func TestScanUntilMarker_KeepsEmptyLines(t *testing.T) {+ const marker = isolatedRunEndMarkerPrefix + "_test"+ input := "a\n\nb\n" + marker + " 0\n"++ var stdout []string+ if _, err := scanUntilMarker(context.Background(), io.NopCloser(strings.NewReader(input)), marker, func(text string) {+ stdout = append(stdout, text)+ }); err != nil {+ t.Fatalf("scanUntilMarker: %v", err)+ }+ if got := strings.Join(stdout, "|"); got != "a||b" {+ t.Fatalf("stdout = %q, want a, empty line, b", got)+ }+}++func TestRunOutputScanner_MarkerAtPieceBoundary(t *testing.T) {+ const marker = isolatedRunEndMarkerPrefix + "_test"+ output := strings.Repeat("a", 64)+ cases := []struct {+ name string+ pieces []string+ }{+ {"boundary inside the marker", []string{output + marker[:5], marker[5:] + " 17"}},+ {"boundary right after the marker", []string{output + marker, " 17"}},+ {"boundary inside the exit code", []string{output + marker + " 1", "7"}},+ }+ for _, tc := range cases {+ t.Run(tc.name, func(t *testing.T) {+ var stdout []string+ scanner := &runOutputScanner{marker: marker, onStdout: func(text string) {+ stdout = append(stdout, text)+ }}+ if !scanner.onLine(tc.pieces[0], false) {+ t.Fatal("scanner stopped before the marker line was complete")+ }+ if scanner.onLine(tc.pieces[1], true) {+ t.Fatal("scanner kept going after the marker line")+ }+ if !scanner.markerSeen || scanner.exitCode != 17 {+ t.Fatalf("markerSeen = %v, exit code = %d, want true, 17", scanner.markerSeen, scanner.exitCode)+ }+ if got := strings.Join(stdout, ""); got != output {+ t.Fatalf("stdout = %q, want %q", got, output)+ }+ })+ }+}diff --git a/components/execd/pkg/runtime/output_lines.go b/components/execd/pkg/runtime/output_lines.gonew file mode 100644index 000000000..7c7bf2d4d--- /dev/null+++ b/components/execd/pkg/runtime/output_lines.go@@ -0,0 +1,107 @@+// Copyright 2026 The OpenSandbox Authors+//+// Licensed under the Apache License, Version 2.0 (the "License");+// you may not use this file except in compliance with the License.+// You may obtain a copy of the License at+//+// http://www.apache.org/licenses/LICENSE-2.0+//+// Unless required by applicable law or agreed to in writing, software+// distributed under the License is distributed on an "AS IS" BASIS,+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+// See the License for the specific language governing permissions and+// limitations under the License.++//go:build !windows++package runtime++import (+ "bufio"+ "bytes"+ "errors"+ "io"+ "unicode/utf8"+)++// maxScanLineBytes bounds the size of one piece of an output line. A longer+// line is delivered in pieces instead of failing the read, so the pipe keeps+// draining and the markers that follow are still seen.+const maxScanLineBytes = 16 * 1024 * 1024++// scanOutputLines calls onLine for each line read from r, without the line+// terminator, as bufio.ScanLines does. A line longer than maxScanLineBytes is+// passed in pieces with complete=false for all but the last piece; pieces+// never split a UTF-8 sequence. Scanning stops when onLine returns false or at+// EOF, and any read error other than io.EOF is returned.+func scanOutputLines(r io.Reader, onLine func(text string, complete bool) bool) error {+ reader := bufio.NewReaderSize(r, 64*1024)+ // line accumulates a line that does not fit in the reader's buffer.+ var line []byte+ for {+ chunk, err := reader.ReadSlice('\n')+ switch {+ case err == nil:+ if len(line) > 0 {+ line = append(line, chunk...)+ chunk, line = line, line[:0]+ }+ if !onLine(string(dropLineEnd(chunk)), true) {+ return nil+ }+ case errors.Is(err, bufio.ErrBufferFull):+ line = append(line, chunk...)+ // Cut only once more than a piece is buffered: the bytes after the+ // cut are then already read, so the last piece is never empty and a+ // CR before the cut is known not to start a CRLF terminator.+ if len(line) <= maxScanLineBytes {+ continue+ }+ cut := lastRuneBoundary(line[:maxScanLineBytes])+ if !onLine(string(line[:cut]), false) {+ return nil+ }+ line = line[:copy(line, line[cut:])]+ default:+ line = append(line, chunk...)+ if len(line) > 0 {+ onLine(string(dropLineEnd(line)), true)+ }+ if errors.Is(err, io.EOF) {+ return nil+ }+ return err+ }+ }+}++// dropLineEnd strips a trailing "\n", "\r\n" or, at EOF, "\r".+func dropLineEnd(line []byte) []byte {+ line = bytes.TrimSuffix(line, []byte("\n"))+ return bytes.TrimSuffix(line, []byte("\r"))+}++// holdBackMarkerPrefix splits an unfinished piece of a long line into the+// part that can be sent now and a tail that may be the start of a marker+// continuing in the next piece. The cut never lands inside a UTF-8 sequence.+func holdBackMarkerPrefix(piece, marker string) (send, held string) {+ cut := max(len(piece)-len(marker)+1, 0)+ for cut > 0 && cut < len(piece) && !utf8.RuneStart(piece[cut]) {+ cut--+ }+ return piece[:cut], piece[cut:]+}++// lastRuneBoundary returns the largest n such that b[:n] does not end inside+// a UTF-8 sequence.+func lastRuneBoundary(b []byte) int {+ for i := len(b) - 1; i >= 0 && i >= len(b)-utf8.UTFMax; i-- {+ if utf8.RuneStart(b[i]) {+ if utf8.FullRune(b[i:]) {+ return len(b)+ }+ return i+ }+ }+ return len(b)+}diff --git a/components/execd/pkg/runtime/output_lines_test.go b/components/execd/pkg/runtime/output_lines_test.gonew file mode 100644index 000000000..588eccdf3--- /dev/null+++ b/components/execd/pkg/runtime/output_lines_test.go@@ -0,0 +1,139 @@+// Copyright 2026 The OpenSandbox Authors+//+// Licensed under the Apache License, Version 2.0 (the "License");+// you may not use this file except in compliance with the License.+// You may obtain a copy of the License at+//+// http://www.apache.org/licenses/LICENSE-2.0+//+// Unless required by applicable law or agreed to in writing, software+// distributed under the License is distributed on an "AS IS" BASIS,+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+// See the License for the specific language governing permissions and+// limitations under the License.++//go:build !windows++package runtime++import (+ "strings"+ "testing"+ "testing/iotest"+ "unicode/utf8"++ "github.com/stretchr/testify/require"+)++type outputPiece struct {+ text string+ complete bool+}++func collectOutputLines(t *testing.T, input string) []outputPiece {+ t.Helper()+ var pieces []outputPiece+ err := scanOutputLines(strings.NewReader(input), func(text string, complete bool) bool {+ pieces = append(pieces, outputPiece{text, complete})+ return true+ })+ require.NoError(t, err)+ return pieces+}++func TestScanOutputLines_MatchesScanLines(t *testing.T) {+ pieces := collectOutputLines(t, "a\r\n\nb\nlast\r")+ require.Equal(t, []outputPiece{+ {"a", true},+ {"", true},+ {"b", true},+ {"last", true},+ }, pieces)+}++func TestScanOutputLines_LineLongerThanReaderBuffer(t *testing.T) {+ long := strings.Repeat("a", 200*1024)+ pieces := collectOutputLines(t, long+"\r\nnext\n")+ require.Equal(t, []outputPiece{+ {long, true},+ {"next", true},+ }, pieces)+}++func TestScanOutputLines_SplitsLongLine(t *testing.T) {+ long := strings.Repeat("a", maxScanLineBytes+100*1024)+ pieces := collectOutputLines(t, long+"\nnext\n")+ require.Equal(t, []outputPiece{+ {long[:maxScanLineBytes], false},+ {long[maxScanLineBytes:], true},+ {"next", true},+ }, pieces)+}++func TestScanOutputLines_LineOfExactlyMaxBytes(t *testing.T) {+ long := strings.Repeat("a", maxScanLineBytes)+ pieces := collectOutputLines(t, long+"\nnext\n")+ require.Equal(t, []outputPiece{+ {long, true},+ {"next", true},+ }, pieces)+}++func TestScanOutputLines_CRLFAtPieceBoundary(t *testing.T) {+ long := strings.Repeat("a", maxScanLineBytes-1)+ pieces := collectOutputLines(t, long+"\r\nnext\n")+ require.Equal(t, []outputPiece{+ {long, true},+ {"next", true},+ }, pieces)+}++func TestScanOutputLines_DoesNotSplitRune(t *testing.T) {+ // The odd prefix puts the piece boundary inside a two-byte rune.+ long := "a" + strings.Repeat("é", maxScanLineBytes/2+64*1024)+ pieces := collectOutputLines(t, long)+ require.Len(t, pieces, 2)+ require.False(t, pieces[0].complete)+ require.Len(t, pieces[0].text, maxScanLineBytes-1)+ for _, piece := range pieces {+ require.True(t, utf8.ValidString(piece.text))+ }+ require.Equal(t, long, pieces[0].text+pieces[1].text)+}++func TestScanOutputLines_StopsWhenCallbackReturnsFalse(t *testing.T) {+ var lines []string+ err := scanOutputLines(strings.NewReader("a\nstop\nb\n"), func(text string, _ bool) bool {+ lines = append(lines, text)+ return text != "stop"+ })+ require.NoError(t, err)+ require.Equal(t, []string{"a", "stop"}, lines)+}++func TestScanOutputLines_ReturnsReadError(t *testing.T) {+ var lines []string+ err := scanOutputLines(iotest.TimeoutReader(strings.NewReader("a\nb")), func(text string, _ bool) bool {+ lines = append(lines, text)+ return true+ })+ require.ErrorIs(t, err, iotest.ErrTimeout)+ require.Equal(t, []string{"a", "b"}, lines)+}++func TestHoldBackMarkerPrefix(t *testing.T) {+ cases := []struct {+ piece, marker, send, held string+ }{+ {"abcdef", "XYZ", "abcd", "ef"},+ {"abcdef", "X", "abcdef", ""},+ {"ab", "WXYZ", "", "ab"},+ // The cut moves back so the two-byte "é" is not split.+ {"abcé", "XY", "abc", "é"},+ }+ for _, tc := range cases {+ send, held := holdBackMarkerPrefix(tc.piece, tc.marker)+ require.Equal(t, tc.send, send, "send for %q, %q", tc.piece, tc.marker)+ require.Equal(t, tc.held, held, "held for %q, %q", tc.piece, tc.marker)+ }+}diff --git a/docs/architecture/data-plane/execd.md b/docs/architecture/data-plane/execd.mdindex 30933d967..89dac5abf 100644--- a/docs/architecture/data-plane/execd.md+++ b/docs/architecture/data-plane/execd.md@@ -60,7 +60,7 @@ Foreground `stdout` and `stderr` event text preserves the command's line endingsA successful foreground `POST /command` ends with `execution_complete` carrying `exit_code: 0`. This optional field is omitted from background startup acknowledgements and code execution events; absence is not an exit status. Non-zero command exits retain `error.exit_code` on the `error` event. Older execd versions omit the successful exit code, so clients may retain their existing foreground-only completion inference. A stream that ends before a terminal event does not establish success.-Bash-session runs stream one merged `stdout` event stream (session stderr is merged into it) with the same line-ending contract: event text preserves `\n`, `\r`, or `\r\n`, and concatenating event text reconstructs the run's output. Blank lines are preserved as events containing only the line ending, and the final event may be an unterminated fragment.+Bash-session runs stream one merged `stdout` event stream (session stderr is merged into it) with the same line-ending contract: event text preserves `\n`, `\r`, or `\r\n`, and concatenating event text reconstructs the run's output. Blank lines are preserved as events containing only the line ending, and the final event may be an unterminated fragment. A line longer than 16 MiB is split across several events, and only the last of them ends with the line ending.Sessions use Bash when the image provides it and fall back to POSIX `sh` on minimal images — commands sent to a fallback session must be `sh`-compatible. Windows sandboxes are supported (environment names are case-insensitive; batch files require shell syntax).diff --git a/sdks/sandbox/javascript/src/api/execd.ts b/sdks/sandbox/javascript/src/api/execd.tsindex 2fe3e8b6e..8dd64f26c 100644--- a/sdks/sandbox/javascript/src/api/execd.ts+++ b/sdks/sandbox/javascript/src/api/execd.ts@@ -190,6 +190,8 @@ export interface paths {* Stdout event text preserves the original line endings (`\n`, `\r`, or `\r\n`). Concatenate* text from the stdout events to recover the run's output; blank lines appear as events* containing only the line ending, and the final event may be an unterminated fragment.+ * A line longer than 16 MiB is split across several events, and only the last of them+ * ends with the line ending.*/post: operations["runInSession"];delete?: never;diff --git a/sdks/sandbox/python/src/opensandbox/api/execd/api/command/run_in_session.py b/sdks/sandbox/python/src/opensandbox/api/execd/api/command/run_in_session.pyindex ff29d2d07..eca79d6f2 100644--- a/sdks/sandbox/python/src/opensandbox/api/execd/api/command/run_in_session.py+++ b/sdks/sandbox/python/src/opensandbox/api/execd/api/command/run_in_session.py@@ -100,6 +100,8 @@ def sync_detailed(Stdout event text preserves the original line endings (`\n`, `\r`, or `\r\n`). Concatenatetext from the stdout events to recover the run's output; blank lines appear as eventscontaining only the line ending, and the final event may be an unterminated fragment.+ A line longer than 16 MiB is split across several events, and only the last of them+ ends with the line ending.Args:session_id (str):@@ -140,6 +142,8 @@ def sync(Stdout event text preserves the original line endings (`\n`, `\r`, or `\r\n`). Concatenatetext from the stdout events to recover the run's output; blank lines appear as eventscontaining only the line ending, and the final event may be an unterminated fragment.+ A line longer than 16 MiB is split across several events, and only the last of them+ ends with the line ending.Args:session_id (str):@@ -175,6 +179,8 @@ async def asyncio_detailed(Stdout event text preserves the original line endings (`\n`, `\r`, or `\r\n`). Concatenatetext from the stdout events to recover the run's output; blank lines appear as eventscontaining only the line ending, and the final event may be an unterminated fragment.+ A line longer than 16 MiB is split across several events, and only the last of them+ ends with the line ending.Args:session_id (str):@@ -213,6 +219,8 @@ async def asyncio(Stdout event text preserves the original line endings (`\n`, `\r`, or `\r\n`). Concatenatetext from the stdout events to recover the run's output; blank lines appear as eventscontaining only the line ending, and the final event may be an unterminated fragment.+ A line longer than 16 MiB is split across several events, and only the last of them+ ends with the line ending.Args:session_id (str):diff --git a/specs/execd-api.yaml b/specs/execd-api.yamlindex 092e86085..ded4de069 100644--- a/specs/execd-api.yaml+++ b/specs/execd-api.yaml@@ -337,6 +337,8 @@ paths:Stdout event text preserves the original line endings (`\n`, `\r`, or `\r\n`). Concatenatetext from the stdout events to recover the run's output; blank lines appear as eventscontaining only the line ending, and the final event may be an unterminated fragment.+ A line longer than 16 MiB is split across several events, and only the last of them+ ends with the line ending.operationId: runInSessiontags:- Command