Skip to content

Commit 27b4d55

Browse files
GiniGini
authored andcommitted
fix: bypass untrusted proxy only for sandbox relay
1 parent 5672689 commit 27b4d55

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

server/onecomputer-sandbox-runner.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ describe('OneComputerSandboxRuntimeAdapter', () => {
114114
expect(launchCommand.indexOf('claude --print')).toBeLessThan(launchCommand.indexOf('rm -f .onevibe-prompt'))
115115
expect(launchCommand.indexOf('rm -f .onevibe-prompt')).toBeLessThan(launchCommand.indexOf('printf %s "$onevibe_exit_code"'))
116116
expect(commands.some((command) => command.includes("export ANTHROPIC_BASE_URL='http://sandbox-reachable-litellm:4100'"))).toBe(true)
117+
expect(commands.some((command) => command.includes('sandbox-reachable-litellm'))).toBe(true)
118+
expect(commands.some((command) => command.includes('export NO_PROXY='))).toBe(false)
117119
expect(commands.some((command) => command.includes("export ANTHROPIC_API_KEY='placeholder'"))).toBe(true)
118120
expect(commands.some((command) => command.includes("export ANTHROPIC_AUTH_TOKEN='test-sandbox-bearer-token'"))).toBe(true)
119121
expect(store.listEvents(task.id).some((event) => event.type === 'run_started' && event.payload.claudeTransport === 'litellm')).toBe(true)
@@ -181,6 +183,9 @@ describe('OneComputerSandboxRuntimeAdapter', () => {
181183
})
182184

183185
it('reuses the conversation-owned sandbox and Claude session for a continuation', async () => {
186+
vi.stubEnv('ONEVIBE_LITELLM_URL', 'http://host-only-litellm:4100')
187+
vi.stubEnv('ONEVIBE_SANDBOX_LITELLM_URL', 'https://sandbox-relay.example')
188+
vi.stubEnv('ONEVIBE_LITELLM_API_KEY', 'test-routing-key')
184189
const root = await mkdtemp(path.join(tmpdir(), 'onevibe-onecomputer-retained-'))
185190
roots.push(root)
186191
const { TaskStore } = await import('./store.js')
@@ -211,6 +216,7 @@ describe('OneComputerSandboxRuntimeAdapter', () => {
211216
expect(commands.filter((command) => command.includes('claude --print'))).toHaveLength(2)
212217
expect(commands.filter((command) => command.includes('claude --print'))[0]).not.toContain('--resume')
213218
expect(commands.filter((command) => command.includes('claude --print'))[1]).toContain("--resume 'session-retained'")
219+
expect(commands.some((command) => command.includes('export NO_PROXY=') && command.includes('sandbox-relay.example'))).toBe(true)
214220
expect(store.getTask(task.id).securityContext).toMatchObject({ runtimeSessionId: 'session-retained', runtimeSessionLeaseGeneration: 1 })
215221
})
216222
})

server/onecomputer-sandbox-runner.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ export class OneComputerSandboxRuntimeAdapter implements RuntimeAdapter {
139139
const configuredClaude = claudeProviderConfig()
140140
const sandboxBaseUrl = process.env.ONEVIBE_SANDBOX_LITELLM_URL?.trim().replace(/\/+$/, '')
141141
?? configuredClaude.childEnv.ANTHROPIC_BASE_URL
142+
const sandboxNoProxyHost = sandboxBaseUrl ? new URL(sandboxBaseUrl).hostname : undefined
142143
const sandboxAuthToken = process.env.ONEVIBE_SANDBOX_LITELLM_AUTH_TOKEN?.trim()
143144
const sandboxApiKey = sandboxAuthToken ? 'placeholder' : configuredClaude.childEnv.ANTHROPIC_API_KEY
144145
const claudeTransport = configuredClaude.configured ? configuredClaude.transport : 'sandbox_preconfigured'
@@ -299,6 +300,10 @@ export class OneComputerSandboxRuntimeAdapter implements RuntimeAdapter {
299300
'set -eu',
300301
'export PATH=/opt/node22/bin:/home/kasm-user/.npm-global/bin:$PATH',
301302
...(sandboxBaseUrl ? [`export ANTHROPIC_BASE_URL=${shellQuote(sandboxBaseUrl)}`] : []),
303+
...(!this.options.gatewayEnforced && sandboxNoProxyHost ? [
304+
`export NO_PROXY="\${NO_PROXY:+$NO_PROXY,}${sandboxNoProxyHost}"`,
305+
`export no_proxy="\${no_proxy:+$no_proxy,}${sandboxNoProxyHost}"`,
306+
] : []),
302307
...(sandboxApiKey ? [`export ANTHROPIC_API_KEY=${shellQuote(sandboxApiKey)}`] : []),
303308
...(sandboxAuthToken ? [`export ANTHROPIC_AUTH_TOKEN=${shellQuote(sandboxAuthToken)}`] : []),
304309
'export CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1',

0 commit comments

Comments
 (0)