Skip to content

fix(box): Keep the env:// secret of an [egress] route in the Runtime profile - #2970

Merged
tejaskash merged 1 commit into
aws:box-integrationfrom
vvargu:box/fix-b7-egress-env-secret
Nov 30, 2026
Merged

tejaskash merged 1 commit into
aws:box-integrationfrom
vvargu:box/fix-b7-egress-env-secret

Conversation

@vvargu

@vvargu vvargu commented Nov 30, 2026 •

Copy link
Copy Markdown

Description

A Box project can have an [egress] route with an env:// secret, as step 4 of docs/box-local-testing.md shows:

[egress.github]
destinations = ["api.github.com"]
secret.ref = "env://GITHUB_TOKEN"

Under agentcore dev, box puts a stand-in in GITHUB_TOKEN, and the agent reads it from the variable. On AgentCore Runtime, the Runtime profile removed the secret from the route, because the gateway target sends the real key. Without the secret, box does not set the variable. So agent code that reads os.environ["GITHUB_TOKEN"] works under dev and gets KeyError on the Runtime. An HTTP [mcp] server with the same secret already keeps it.

Calls to the host still work on the Runtime: the egress-github gateway target adds the real key from AgentCore Identity. Only agent code that requires the variable fails, such as os.environ["GITHUB_TOKEN"] or a library that stops when the variable is missing.

This change keeps an env:// secret on the Runtime route of an [egress] entry, without inject, as mcpServer does. A secret of another kind still goes. egressRoute and mcpServer now use one helper, standInSecret. This is the form that strands-agents/box#311 documents for a secret beside a backend: box gives the agent a placeholder, removes it from the request, and never reads the variable.

.box/<runtime>/aws/profile.toml before and after

For the local entry above, build writes this route.

Before:

[egress.github]
destinations = [ "api.github.com" ]

[[egress.github.backends]]
url = "${{ inputs.gateway.url }}/egress-github"

[egress.github.backends.auth]
ref = "aws://"

[egress.github.backends.auth.aws]
service = "bedrock-agentcore"
region = "${{ inputs.aws.region }}"

After:

[egress.github]
destinations = [ "api.github.com" ]

[egress.github.secret]
ref = "env://GITHUB_TOKEN"

[[egress.github.backends]]
url = "${{ inputs.gateway.url }}/egress-github"

[egress.github.backends.auth]
ref = "aws://"

[egress.github.backends.auth.aws]
service = "bedrock-agentcore"
region = "${{ inputs.aws.region }}"

The only difference is the [egress.github.secret] table. The gateway backend and its SigV4 auth do not change. A local secret.inject is not copied, because box refuses it beside a backend.

Checked with box 0.3.3 (the pinned release), with GITHUB_TOKEN unset as on the Runtime:

Route form What the agent sees
Backend, no secret (before this change) GITHUB_TOKEN unset
Backend and env:// secret (this change) a strands_box_… stand-in
Backend and env:// secret with inject box refuses: a destination secret.inject has no effect beside a backend
Two routes with the same env:// variable a stand-in, no refusal

Related Issue

No issue. Review finding B7 on #2922 (the Runtime route of an [egress] entry loses its env:// secret).

Documentation PR

Not applicable. The docs do not describe the removed secret. The table at the top of rules/gateway.ts is updated.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update
  • Other (please describe):

Testing

  • I ran bun test: 6,769 pass and 3 fail with box 0.3.3 on PATH. I fixed two of the failures in this PR. The third, the box on PATH > resolves a profile into the rules the tests fake in boxProfileResolver.test.ts, fails the same way on box-integration without this change.
  • I ran the relevant end-to-end tests with bun run test:e2e. Not run: they deploy real resources. A local build of a CodeZip Box project now writes [egress.github.secret] ref = "env://GITHUB_TOKEN" beside the gateway backend in .box-dist/profile.toml.
  • I ran bun run typecheck
  • I ran bun run lint:check
  • I ran bun run format:check
  • I ran bun run audit
  • I ran bun run secrets:check
  • I ran bun run build
  • If I modified src/assets/, I updated affected snapshots. Not applicable.
  • If I re-recorded fixtures or golden files, every change is explained. Not applicable: the old-renderer fixture is unchanged; the parity helper notes the one intended difference.
  • This PR does not change command.md

Tests changed or added:

  • rules/gateway.test.ts: the route keeps the env:// secret. A new test covers an entry with two hosts, inject removed, and a signed secret dropped. A new test gives the route to the box on PATH and checks that box profile show accepts it with no value in the variable (skipped when there is no box on PATH).
  • manager.boxNetwork.test.ts: the two build tests expect the secret on the github route.

Checklist

  • I have read the CONTRIBUTING document
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature, or no new docs are needed
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the
terms of your choice.

@codecov-commenter

codecov-commenter commented Nov 30, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.94%. Comparing base (7511e8a) to head (824145a).

Additional details and impacted files
@@               Coverage Diff                @@
##           box-integration    #2970   +/-   ##
================================================
  Coverage            96.94%   96.94%           
================================================
  Files                  780      780           
  Lines                70806    70813    +7     
================================================
+ Hits                 68645    68652    +7     
  Misses                2161     2161           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@vvargu
vvargu requested review from leo237 and mquang-amazon and removed request for leo237 November 30, 2026 22:56
@vvargu
vvargu marked this pull request as ready for review November 30, 2026 22:56
@vvargu
vvargu requested a review from a team November 30, 2026 22:56
…profile

The Runtime profile removed the secret from each [egress] route that goes
through the Box gateway. Without the secret, box does not set the variable,
so an agent that reads its stand-in from the variable under agentcore dev
gets KeyError on AgentCore Runtime. An HTTP [mcp] server already keeps its
env:// secret. Calls to the host still work: the gateway target adds the
real key. Only agent code that requires the variable fails.

Keep an env:// secret on the route without inject, as for an [mcp] server.
Drop a secret of another kind. Box 0.3.3 accepts this form with no value in
the variable, gives the agent a stand-in, and refuses inject beside a
backend, as strands-agents/box#311 documents.

For this local profile entry:

    [egress.github]
    destinations = ["api.github.com"]
    secret.ref = "env://GITHUB_TOKEN"

.box/<runtime>/aws/profile.toml before this change:

    [egress.github]
    destinations = [ "api.github.com" ]

    [[egress.github.backends]]
    url = "${{ inputs.gateway.url }}/egress-github"

    [egress.github.backends.auth]
    ref = "aws://"

    [egress.github.backends.auth.aws]
    service = "bedrock-agentcore"
    region = "${{ inputs.aws.region }}"

.box/<runtime>/aws/profile.toml after this change:

    [egress.github]
    destinations = [ "api.github.com" ]

    [egress.github.secret]
    ref = "env://GITHUB_TOKEN"

    [[egress.github.backends]]
    url = "${{ inputs.gateway.url }}/egress-github"

    [egress.github.backends.auth]
    ref = "aws://"

    [egress.github.backends.auth.aws]
    service = "bedrock-agentcore"
    region = "${{ inputs.aws.region }}"

Add a test that gives the route to the box on PATH.
@vvargu
vvargu force-pushed the box/fix-b7-egress-env-secret branch from 8fe5179 to 824145a Compare November 30, 2026 23:03
@tejaskash
tejaskash merged commit 40b8f33 into aws:box-integration Nov 30, 2026
6 checks passed
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.

4 participants